Another option, if you really prefer the syntax of the query expression, would be to build a query chain for several 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 exactly the same execution performance.
Jacob Carpenter
source share