EF和Linq OrderBy使用两个参数

Gib*_*boK 9 c# linq entity-framework

我使用EF 4和C#.

我需要使用属于两个不同实体的两个属性来订购此查询的结果.

在我的情况下,我想订购gt.GroupTypeId和它subset by 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
            };
Run Code Online (Sandbox Code Playgroud)

Jam*_*ill 13

简单的例子:

var orderedList = cnt.OrderBy(x => x.GroupTypeId).ThenBy(x => x.ContentId);
Run Code Online (Sandbox Code Playgroud)

  • @vittore:你的语句是否有参考"LINQ查询比扩展方法慢"?我从来没有听说过这个. (3认同)