36 lines
1.2 KiB
C#
36 lines
1.2 KiB
C#
using ContactService.Domain.Entities;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
|
|
namespace ContactService.Infrastructure.Configs
|
|
{
|
|
public class FriendConfig : IEntityTypeConfiguration<Friend>
|
|
{
|
|
public void Configure(EntityTypeBuilder<Friend> 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");
|
|
});
|
|
|
|
|
|
|
|
}
|
|
}
|
|
}
|