GibboK
GibboK

Reputation: 73908

EF and Linq OrderBy using two Parameters

I use EF 4 and 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.

PS: I'm not sure if my title is appropriate, if you think not, let me know I will change it :-)

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

Upvotes: 9

Views: 5567

Answers (1)

James Hill
James Hill

Reputation: 61793

Simple example:

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

Upvotes: 14

Related Questions