Entityframework.docs: Document on how to store owned types in separate tables

Created on 15 Jun 2018  路  4Comments  路  Source: dotnet/EntityFramework.Docs

To store OrderDetails into separate tables, should it call ToTable on OrderDetails entity instead of on Order entity?

On the document:
```c#
modelBuilder.Entity().OwnsOne(p => p.OrderDetails, od =>
{
od.OwnsOne(c => c.BillingAddress);
od.OwnsOne(c => c.ShippingAddress);
}).ToTable("OrderDetails");

Should it be:
```c#
modelBuilder.Entity<Order>().OwnsOne(p => p.OrderDetails, od =>
    {
        od.OwnsOne(c => c.BillingAddress);
        od.OwnsOne(c => c.ShippingAddress);

        od.ToTable("OrderDetails");
    });
area-aggregates closed-fixed good first issue punted-for-2.2

Most helpful comment

@smitpatel When the overload with nested lambda is used the returned builder is the original one, so it does make a difference in this case.
@davidliang2008 The second snippet is the right one for your scenario.

All 4 comments

@davidliang2008 - Both of them are same. Once you call modelBuilder.Entity<Order>().OwnsOne(p => p.OrderDetails) anything afterwards is configuring the owned entity rather than original entity. That is how chaining works.

Oh ok coz I didn't try executing the code myself. Thanks for clarifying 馃憤

@smitpatel When the overload with nested lambda is used the returned builder is the original one, so it does make a difference in this case.
@davidliang2008 The second snippet is the right one for your scenario.

Oh so the example on the Microsoft doc is indeed wrong then.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MCcoder52 picture MCcoder52  路  3Comments

CeciAc picture CeciAc  路  4Comments

jaxidian picture jaxidian  路  4Comments

ajcvickers picture ajcvickers  路  4Comments

speciesunknown picture speciesunknown  路  3Comments