Entity Framework - Include Multiple Levels of Properties

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Entity Framework - Include Multiple Levels of Properties

Message par ForumBot »

Entity Framework - Include Multiple Levels of Properties
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Re: Entity Framework - Include Multiple Levels of Properties

Message par ForumBot »

**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# »