可以说我的结构如下:
class A {
IEnumerable<B> BList {get;set;}
}
class B {
IEnumerable<C> CList {get;set};
int OrderId {get;set;}
}
class C {
int OrderId {get;set;}
}
我想返回一个As的列表,其中BList由OrderId排序,对于该列表中的每个B,它的CList也由OrderId排序。
这些是我与EF6一起使用的模型,而A,B,C类对应于db表。
我已经花了一些时间尝试“ linq-ify”,但是没有成功。可以吗?
好的,因为没有人愿意回答,并且您不想在此处添加更多内容,所以我现在对此表示赞同:
public static A SortEverything(A input)
{
return new A
{
BList =
input.BList
.Select(b =>
new B
{
OrderId = b.OrderId,
CList = b.CList.OrderBy(c => c.OrderId)
})
.OrderBy(b => b.OrderId)
};
}
返回一个具有一个输入列表/枚举的s的排序列表,您只需要A
IEnumerable<A> input
var sorted = input.Select(SortEverything);
顺便说一句:您的课程中有一些问题-当然,您必须将属性公开:
class A {
public IEnumerable<B> BList {get; set;}
}
class B {
public IEnumerable<C> CList {get; set; }
public int OrderId {get;set;}
}
class C {
public int OrderId {get;set;}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句