Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
            };
like image 458
GibboK Avatar asked Oct 04 '11 15:10

GibboK


1 Answers

Simple example:

var orderedList = cnt.OrderBy(x => x.GroupTypeId).ThenBy(x => x.ContentId);
like image 92
James Hill Avatar answered Oct 21 '22 09:10

James Hill