【发布时间】:2021-10-16 15:31:58
【问题描述】:
我正在使用带有 Asp Net Core 的 EF Core。
我有一个User.cs 课程
public class User
{
public int Id { get; set; }
public Contact Contact { get; set; }
}
还有一个Contact.cs 类
public class Contact
{
public List<PhoneNumber> PhoneNumbers { get; set; }
}
这是我的建造者
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.Entity<User>().OwnsOne(x => x.Contact);
}
所以我的问题是关于“如何设置我的联系人(嵌套在用户中)可能有一个电话号码对象列表”? 我想要的只是所有内容都存储在一张表中,问题不在于每个用户存储多个电话号码。
【问题讨论】:
-
“所有内容都存储在一个表中”通常是个坏主意。
标签: asp.net-core entity-framework-core