2008-10-31 37 views
6

我在我的訂單中放了什麼?我想按名稱訂購。我已經移動了命令,因爲我讀了它需要最後完成。如何使用匿名類型獲取我的訂單?

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(); 

回答

13

只是做

.OrderBy(doc => doc.Name) 
+0

謝謝,我正試着做name => name – ScottG 2008-10-31 19:08:28

3

另一種選擇,如果你真的喜歡查詢表達式語法將鏈查詢建設跨越多個語句:

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; 

由於所有的這些方法被推遲,這將導致完全相同的執行性能。