Entity Framework - Include Multiple Levels of Properties
Entity Framework - Include Multiple Levels of Properties
Entity Framework - Include Multiple Levels of Properties
Re: Entity Framework - Include Multiple Levels of Properties
**For EF 6**
```
using System.Data.Entity;
query.Include(x => x.Collection.Select(y => y.Property))
```
Make sure to add `using System.Data.Entity;` to get the version of `Include` that takes in a lambda.
**For EF Core**
Use the new method [`ThenInclude`](https://learn.microsoft.com/en-us/ef/core/querying/related-data#including-multiple-levels)
```
using Microsoft.EntityFrameworkCore;
query.Include(x => x.Collection)
.ThenInclude(x => x.Property);
```
```
using System.Data.Entity;
query.Include(x => x.Collection.Select(y => y.Property))
```
Make sure to add `using System.Data.Entity;` to get the version of `Include` that takes in a lambda.
**For EF Core**
Use the new method [`ThenInclude`](https://learn.microsoft.com/en-us/ef/core/querying/related-data#including-multiple-levels)
```
using Microsoft.EntityFrameworkCore;
query.Include(x => x.Collection)
.ThenInclude(x => x.Property);
```