How to get the 2 level data using ef core?

mc 3,726 Reputation points
public Class MyCataA {  
 public int Id{get;set}  
 public int TopId{get;set;}  
public Class IMGA  
       public int Id{get;set;}  
       public string ImageUrl{get;set;}  
       public int CateId{get;set;}  

I am using entityframework and I want to get the list of the images which CateId is in MyCateA;

There is a list of maybe 10 of MyCateA that TopId= 0 and others TopId = its Top Category.

how to get the list?

now I have to get the list of TopId= 10 and using for to get each sub Categories and then get the images.

Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
702 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. AgaveJoe 26,166 Reputation points

    Use ThenInclude to include multiple levels. Please read the official documentation.

    Eager Loading of Related Data