My model is:
public class WhereClause
{
[Key]
public int Id { get; set; }
public int? ColumnId { get; set; }
[StringLength(100)]
public string Logic { get; set; }
[StringLength(250)]
public string Value { get; set; }
public List<WhereClause?> WhereClauses { get; set; }
public short HierarchyCount { get; set; }
}
As you see, model contain self-list of object and i want to include all inner list in any level at one fetch. Based on Entity Framework - Include Multiple Levels of Properties I know that can use Include
and ThenInclude
but i don't know how many level of inner list in model. currently i store HierarchyCount
property at model for this purpose and create string of include like .Include("WhereClauses,WhereClauses.WhereClauses,WhereClauses.WhereClauses.WhereClauses")
. but are there any solution better of that?
Update:
WhereClause
is part of Report
Table and can't load whole WhereClause
for every report query:
public class Report:ModelAbstract
{
[Key]
public int Id { get; set; }
[Required]
[StringLength(100)]
public string Name { get; set; }
[Required]
public Table Table { get; set; }
public List<SelectClause> SelectClauses { get; set; }
[ForeignKey("WhereClause")]
public int? WhereClauseId { get; set; }
public WhereClause WhereClause { get; set; }
}