Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get my orderby to work using an anonymous type?

Tags:

linq

What do I put in my order by?? I want to order by Name. I have moved the orderby after the distinct because I read that it needs to be done last.

   var result = (from r in db.RecordDocs
                  where r.RecordID == recordID
                  select new
                             {
                                 DocTypeID = r.Document.DocType.DocTypeID,
                                 Name = r.Document.DocType.Name,
                                 Number = r.Document.DocType.Number
                             }
                 ).Distinct().OrderBy( );
like image 243
ScottG Avatar asked Oct 31 '08 18:10

ScottG


1 Answers

Just do

.OrderBy(doc => doc.Name)
like image 149
Jacob Carpenter Avatar answered Sep 17 '22 23:09

Jacob Carpenter