Yuriy Mayorov Yuriy Mayorov - 4 months ago 30
C# Question

entity framework get entities with child collection with self order

I have a entity(SystemUnit), which contains collection of sub entities(Roles):

public partial class SystemUnit
public SystemUnit()
this.Roles = new HashSet<Role>();
this.Childs = new HashSet<SystemUnit>();

public int Id { get; set; }
public Nullable<int> ParentId { get; set; }
public int SystemUnitTypeId { get; set; }
public string Name { get; set; }

public virtual SystemUnitType SystemUnitType { get; set; }
public virtual ICollection<Role> Roles { get; set; }
public virtual ICollection<SystemUnit> Childs { get; set; }
public virtual SystemUnit Parent { get; set; }

I need using entity framework to get all system units, ordered by Id Asc with included Roles, ordered by id desc. Newbee in linq (


The Roles included according to SystemUnit objects. If SystemUnit object has Id ordered by desc so in this way roles can not be orderby dec. They will retrieve according to SystemUnit objects