tags:

views:

92

answers:

2

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( );
+7  A: 

Just do

.OrderBy(doc => doc.Name)
Jacob Carpenter
thank you, I was trying to do name => name
Scott
+2  A: 

Another option, if you really prefer the query expression syntax would be to chain your query construction across multiple statements:

var query = 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
    };

query = query.Disctinct();
query = from doc in query orderby doc.Name select doc;

Since all of these methods are deferred, this will result in the exact same execution performance.

Jacob Carpenter