小编Dav*_*ous的帖子

Entity Framework Core OwnsOne 创建单独的表,而不是按预期将属性添加到同一表

我认为 Entity Framework Core 拥有的类型默认会添加到与其所有者相同的表中。但我在迁移中没有看到这一点。

有人会告诉我这里吗?

有没有办法通过将 Name 属性直接添加到 Person 表来获得所需的迁移?

public class Person
{
    public Name Name { get; set; }
}

public class Name
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
}

public class PersonConfiguration : IEntityTypeConfiguration<Person>
{
    public void Configure(EntityTypeBuilder<Person> person)
    {
          person.OwnsOne(p => p.Name);
    }
}
Run Code Online (Sandbox Code Playgroud)

dotnet ef migrations add DidNotSeeThatComing 结果是

public partial class DidNotSeeThatComing : Migration
{
    protected override void Up(MigrationBuilder migrationBuilder)
    {
        migrationBuilder.CreateTable(
            name: "Name", …
Run Code Online (Sandbox Code Playgroud)

entity-framework-core ef-core-2.1 owned-types entity-framework-migrations

5
推荐指数
1
解决办法
2992
查看次数