How to get the 2 level data using ef core?

mc 3,701 Reputation points
2022-08-17T09:56:46.607+00:00
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.
697 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. AgaveJoe 26,141 Reputation points
    2022-08-17T11:04:45.907+00:00

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

    Eager Loading of Related Data
    Relationships