У меня есть вложенные модели с именами PositionLevel
, PositionLevelCompanyLookup
, Company
, CompanySub
. Я хочу получить все данные моделей в функции GetDetail
с помощью ThenInclude
. Но все данные модели не были получены, и я не мог найти причину для этого.
Как мне это сделать?
public class PositionLevel : DynexModel
{
public string Description { get; set; }
[JsonIgnore]
public List<PositionLevelCompanyLookup> Companies { get; set; }
[NotMapped]
public virtual List<Company> CompanyList => this.Companies?.Select(p => p.Company).ToList();
}
public class PositionLevelCompanyLookup : DynexModel
{
public int PositionLevelId { get; set; }
public PositionLevel PositionLevel { get; set; }
public int CompanyId { get; set; }
public Company Company { get; set; }
}
public class Company : DynexModel
{
public string Name { get; set; }
[JsonIgnore]
public List<CompanySub> SubCompanies { get; set; }
[NotMapped]
public virtual List<Company> SubCompanyList => this.SubCompanies?.Select(p => p.SubCompany).ToList();
}
public class CompanySub : DynexModel
{
public int CompanyId { get; set; }
public Company Company { get; set; }
public int SubCompanyId { get; set; }
public Company SubCompany { get; set; }
}
public ActionResult<PositionLevel> GetDetail(int id)
{
var res = _context.Entity<PositionLevel>()
.Include(p => p.Companies)
.ThenInclude(p => p.Company)
.ThenInclude(p => p.SubCompanies)
.FirstOrDefault(p => p.Id == id);
return res ;
}