Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions entity-framework/core/modeling/owned-entities.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,25 @@ When querying the owner the owned types will be included by default. It is not n

[!code-csharp[DetailedOrderQuery](../../../samples/core/Modeling/OwnedEntities/Program.cs?name=DetailedOrderQuery)]

An owned entity can't be tracked without its owner. If a tracking query projects an owned entity without projecting its owner, EF Core throws an exception, because the owned instance can't be updated or deleted on its own. For example, the following query throws `A tracking query projects owned entity without corresponding owner in result. Owned entities cannot be tracked without their owner.`:

```csharp
var billingAddresses = await context.Orders
.Select(o => o.OrderDetails.BillingAddress)
.ToListAsync();
```

If the owned entity is queried for read-only purposes, call `AsNoTracking`:

```csharp
var billingAddresses = await context.Orders
.Select(o => o.OrderDetails.BillingAddress)
.AsNoTracking()
.ToListAsync();
```

If the owned entity should be tracked so it can be updated later, project the owner as well. Projecting individual properties of an owned entity instead of the owned entity itself doesn't require `AsNoTracking`, because no entity is tracked in that case.

## Limitations

Some of these limitations are fundamental to how owned entity types work, but some others are restrictions that we may be able to remove in future releases:
Expand Down
Loading