Posts Entity framework LINQ w/ nested table
Post
Cancel

Entity framework LINQ w/ nested table

Using Lambda Expression

1
2
3
4
5
6
using (var context = new EntityContext())
{
    var customers = context.Customers
            .Include(i => i.Invoices.Select(it => it.Items))
            .ToList();
}

Using String Path

1
2
3
4
5
6
using (var context = new EntityContext())
{
    var customers = context.Customers
            .Include("Invoices.Items")
            .ToList();
}

Also the two of them will load all customers, their related invoices, and the items of each invoice.

In Entity Framework Core use .ThenInclude

1
2
3
4
5
6
//src - https://stackoverflow.com/a/47555838
//ref - https://docs.microsoft.com/en-us/ef/core/querying/related-data
var blogs = context.Blogs
    .Include(blog => blog.Posts)
        .ThenInclude(post => post.Author)
    .ToList();

src - https://entityframework.net/include-multiple-levels

origin - https://www.pipiscrew.com/?p=18561 entity-framework-linq-w-nested-table

This post is licensed under CC BY 4.0 by the author.
Contents

Trending Tags