如何排序由实体框架返回内部列表? [英] How to sort inner list that is returned by entity framework?
本文介绍了如何排序由实体框架返回内部列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何排序的实体框架?
公共类X
返回的对象的内部集合{
公共字符串域{搞定;设置;}
公共EntityCollection< Y>伊苏{搞定;设置;}
}
公共Y类
{
公共字符串域{搞定;设置;}
}
$ B $从X B在entities.Xs
排序依据x.Field
选择[x]
有没有修改这个LINQ查询返回在X对象,也有在Y对象排序的方法吗? ?还是我当谈到回手动排序在Y名单
编辑:
这代码必须返回X的集合类型对象,匿名打字不符合当前项目的要求。
解决方案
<$在entities.Xs 排序依据x.Field
$ p p>
VAR排序列表=从X选择新{
场= x.Field,通过= $ b $(选择Y在x.Ys
排序依据y.Field
选择Y)
};
编辑:
。如果你不想匿名类型那么这样做:
VAR排序列表=从entities.Xs
排序依据x.Field $ b $宽x选择新的X {
场= x.Field,通过=(在x.Ys
排序依据y.Field
选择Y选择Y)
$ b $};
How do I sort the inner collection of an object returned by the entity framework?
public class X
{
public string Field {get; set;}
public EntityCollection<Y> Ys {get; set;}
}
public class Y
{
public string Field {get; set;}
}
from x in entities.Xs
orderby x.Field
select x
Is there a way to modify this LINQ query to return the X objects and also have the Y objects sorted? Or do I have to manually sort the Y list when it comes back?
EDIT:
This code must return a collection of X typed objects, anonymous typing doesn't meet the current project's requirements.
解决方案
var sortedList = from x in entities.Xs
orderby x.Field
select new {
Field = x.Field,
y = (select y in x.Ys
orderby y.Field
select y)
};
Edited: If you don't want anonymous types then do this:
var sortedList = from x in entities.Xs
orderby x.Field
select new X {
Field = x.Field,
y = (select y in x.Ys
orderby y.Field
select y)
};
这篇关于如何排序由实体框架返回内部列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文