using ContactService.Domain.Entities; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace ContactService.Infrastructure.Configs { public class FriendConfig : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { builder.ToTable("friends"); builder.HasKey(x => x.Id); builder.OwnsOne(x => x.Owner, owner => { owner.WithOwner(); // 🔥 关键:明确归属 owner.Property(p => p.Id).HasColumnName("OwnerId").IsRequired(); owner.Property(p => p.NickName).HasColumnName("OwnerNickName"); owner.Property(p => p.Avatar).HasColumnName("OwnerAvatarUrl"); }); builder.OwnsOne(x => x.Target, target => { target.WithOwner(); // 🔥 关键 target.Property(p => p.Id).HasColumnName("TargetId").IsRequired(); target.Property(p => p.NickName).HasColumnName("TargetNickName"); target.Property(p => p.Avatar).HasColumnName("TargetAvatarUrl"); }); } } }