I'm trying to upgrade the OwnedTypes sample to EF Core 3.0 Preview 8 but when I run the project it can't create the database.
When Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade.EnsureCreated()
is called the following exception is thrown:
Microsoft.Data.SqlClient.SqlException: 'Cascading foreign key 'FK_OrderDetails_DetailedOrders_OrderId' cannot be created where the referencing column 'OrderDetails.OrderId' is an identity column. Could not create constraint or index. See previous errors.'
What previous errors? 🤔
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
#region OwnsOneNested
modelBuilder.Entity<DetailedOrder>().OwnsOne(p => p.OrderDetails, od =>
{
od.OwnsOne(c => c.BillingAddress);
od.OwnsOne(c => c.ShippingAddress);
});
#endregion
#region OwnsOneTable
modelBuilder.Entity<DetailedOrder>().OwnsOne(p => p.OrderDetails, od =>
{
od.OwnsOne(c => c.BillingAddress);
od.OwnsOne(c => c.ShippingAddress, sa =>
{
sa.Ignore(p => p.IgnoreMe);
});
od.ToTable("OrderDetails");
});
#endregion
}
I assume there is something in the 3.0 breaking changes list I need to follow?
od.ToTable("OrderDetails");
to map OrderDetails
to the same table as DetailedOrder
od.Property("OrderId").ValueGeneratedNever();
to disable marking the OrderId
column as identity