添加项目文件。
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
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");
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user