EF和Linq OrderBy使用两个参数

我使用EF 4和C#.

我需要使用属于两个不同实体的两个属性对此查询的结果进行排序.

在我的情况下,我想通过gt.GroupTypeId及其子集由cnt.ContentId排序.

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);

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 'EastRiver' 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...