EF core 6 then Include issue

Mohan Chanchal 0 Reputation points
2023-05-30T12:00:28.49+00:00

In EF core 3.1 I am able to include a collection of object using include statement. After that then include is not working in EF core 6

eg

public class Parent
{
    public int Id { get; set; }
    public string Name { get; set; }
    public List<Child> Children { get; set; }
}

public class Child
{
    public int Id { get; set; }
    public string Name { get; set; }
    public int ParentId { get; set; }
    public Parent Parent { get; set; }
    public List<GrandChild> GrandChildren { get; set; }
}

public class GrandChild
{
    public int Id { get; set; }
    public string Name { get; set; }
    public int ChildId { get; set; }
    public Child Child { get; set; }
}



var result = dbContext.Parents
    .Include(p => p.Children) // Include the list of Children
        .ThenInclude(c => c.GrandChildren) // Include the list of GrandChildren inside Children
    .ToList();

This query not working anymore please update why this feature is removed?

Developer technologies ASP.NET ASP.NET Core
Developer technologies .NET Other
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.