I thought that Entity Framework Core owned types by default get added to the same table as their owner. But I'm not seeing this in the migration.
Would someone clue me in here?
Is there a way to get the desired migration with Name properties added directly to the Person table?
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);
}
}
dotnet ef migrations add DidNotSeeThatComing
results in
public partial class DidNotSeeThatComing : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Name",
columns: table => new
{
FirstName = table.Column<string>(type: "varchar", nullable: true),
LastName = table.Column<string>(type: "varchar", nullable: true),
PersonId = table.Column<Guid>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Name", x => x.PersonId);
table.ForeignKey(
name: "FK_Name_Person_PersonId",
column: x => x.PersonId,
principalTable: "Person",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
);
}
}
I created this myself unwittingly with this configuration code
Here is the workaround I'm using