Entity Framework - Include Multiple Levels of Properties

前端 未结 8 806
囚心锁ツ
囚心锁ツ 2020-11-22 08:43

The Include() method works quite well for Lists on objects. But what if I need to go two levels deep? For example, the method below will return ApplicationServers with the i

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 09:07

    EF Core: Using "ThenInclude" to load mutiple levels: For example:

    var blogs = context.Blogs
        .Include(blog => blog.Posts)
            .ThenInclude(post => post.Author)
            .ThenInclude(author => author.Photo)
        .ToList();
    

提交回复
热议问题