为什么迁移中没有显示某些属性?



我在Visual Studio 2019中运行EF Core 3.1。

我有两个类:电话号码和电话号码类型。

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.OnModelCreate中,我有(连接是电话号码的主要实体(:

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 不在迁移中。 为什么不呢?什么原因可能导致这种情况?

我想通了 - 我需要属性上的二传手。

最新更新