Yuriy Mayorov Yuriy Mayorov - 1 year ago 153
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 (

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download