Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 实体框架获取具有自排序子集合的实体_C#_Linq_Entity Framework - Fatal编程技术网

C# 实体框架获取具有自排序子集合的实体

C# 实体框架获取具有自排序子集合的实体,c#,linq,entity-framework,C#,Linq,Entity Framework,我有一个实体(SystemUnit),其中包含子实体(角色)的集合: 公共部分类系统单元 { 公共系统股() { this.Roles=new HashSet(); this.Childs=newhashset(); } 公共int Id{get;set;} 公共可为空的ParentId{get;set;} public int SystemUnitTypeId{get;set;} 公共字符串名称{get;set;} 公共虚拟SystemUnitType SystemUnitType{get;s

我有一个实体(SystemUnit),其中包含子实体(角色)的集合:

公共部分类系统单元
{
公共系统股()
{
this.Roles=new HashSet();
this.Childs=newhashset();
}
公共int Id{get;set;}
公共可为空的ParentId{get;set;}
public int SystemUnitTypeId{get;set;}
公共字符串名称{get;set;}
公共虚拟SystemUnitType SystemUnitType{get;set;}
公共虚拟ICollection角色{get;set;}
公共虚拟ICollection子项{get;set;}
公共虚拟系统单元父级{get;set;}
}

我需要使用实体框架来获取所有系统单元,按Id Asc和包含的角色排序,按linq中的Id desc.Newbee排序(

为此,您首先需要一个上下文实体,然后将您的系统单元实体作为对象添加到其中。例如:

public class entityContext{

    public DbSet<SystemUnit> SystemUnit { get; set;}

}
公共类entityContext{
公共数据库集系统单元{get;set;}
}
然后在需要调用实体的方法中,写入:

entityContext ec = new entityContext();
 List<SystemUnit> systemUnit = (from su in ec.SystemUnit .Include("Roles") orderby su.Id Asc).ToList();
entityContext ec=新的entityContext();
List systemUnit=(从ec.systemUnit.Include(“角色”)中的su按su.Id Asc.ToList()排序);

根据SystemUnit对象包含的角色。如果SystemUnit对象的Id由desc排序,那么在dec之前无法对角色进行排序。他们将根据SystemUnit对象检索可能重复的感谢,例如,M,但我如何包含按Id desc排序的角色?我在这里找到答案
entityContext ec = new entityContext();
 List<SystemUnit> systemUnit = (from su in ec.SystemUnit .Include("Roles") orderby su.Id Asc).ToList();