简体   繁体   English

EF和Linq OrderBy使用两个参数

[英]EF and Linq OrderBy using two Parameters

I use EF 4 and C#. 我使用EF 4和C#。

I need order the result of this query with two Properties belonging to two different Entities . 我需要使用属于两个不同实体的两个属性来订购此查询的结果

In my case I would like order by gt.GroupTypeId and its subset by cnt.ContentId . 在我的情况下,我想按gt.GroupTypeId ,其subset by cnt.ContentId

PS: I'm not sure if my title is appropriate, if you think not, let me know I will change it :-) PS:我不确定我的标题是否合适,如果你不认为,请告诉我,我会改变它:-)

from cnt in context.CmsContents
            from gt in cnt.CmsGroupsTypes
            join t in context.CmsTypes
            on cnt.TypeContent equals t.TypeContent
            join m in context.CmsModes
            on cnt.ModeContent equals m.ModeContent
            orderby gt.GroupTypeId // Problem here
            select new
            {
            cnt.ContentId,
            cnt.Title,
            gt.TypeGroup,
            gt.GroupTypeId,
            TypeContentDescription = t.Description,
            ModeContentDescription = m.Description,
            cnt.IsPublished
            };

简单的例子:

var orderedList = cnt.OrderBy(x => x.GroupTypeId).ThenBy(x => x.ContentId);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM