【发布时间】:2020-05-19 00:26:29
【问题描述】:
我在 Visual Studio 2019 中运行 EF Core 3.1。
我有两个类:PhoneNumber 和 PhoneNumberType。
public class PhoneNumber : ValueObject
{
public int Id { get; }
[Phone]
public string PhNumber { get; }
//public int? PhoneNumberTypeId { get; private set; }
public PhoneNumberType PhoneType { get; }
}
public class PhoneNumberType : ValueObject
{
public int Id { get; }
public string Description { get; }
}
在我的 DBContext.OnModelCreating 我有(连接是 PhoneNumber 的主要实体):
modelBuilder.Entity<Connection>().OwnsMany(s => s.PhoneNumbers, a => a.HasOne(b => b.PhoneType).WithMany().HasPrincipalKey(c => c.Id));
但是,当我创建迁移时,这就是创建的内容:
migrationBuilder.CreateTable(
name: "PhoneNumber",
columns: table => new
{
ConnectionId = table.Column<int>(nullable: false),
Id1 = table.Column<int>(nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
PhoneTypeId = table.Column<int>(nullable: true)
},
migrationBuilder.CreateTable(
name: "PhoneNumberType",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:Identity", "1, 1")
}
请注意,PhoneNumber.PhNumber 和 PhoneNumberType.Description 不在迁移中。为什么不?这是什么原因造成的?
【问题讨论】:
标签: c#-8.0 entity-framework-core-3.1 entity-framework-core-migrations