Entity Framework - Include Multiple Levels of Properties

Clippy
Messages : 22157
Inscription : mer. 22 avr. 2026, 17:33

Entity Framework - Include Multiple Levels of Properties

Message par Clippy »

Entity Framework - Include Multiple Levels of Properties
Clippy
Messages : 22157
Inscription : mer. 22 avr. 2026, 17:33

Re: Entity Framework - Include Multiple Levels of Properties

Message par Clippy »

**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);

```
Répondre

Revenir à « .NET & C# »