2009-05-19 40 views
2

我在將此查詢表達式轉換爲我的LINQ表達式時遇到了一些痛苦。將組表的SQL表達式轉換爲LINQ

SELECT 
    r.Disc_code 
    ,r.SEX 
FROM RACE r  
WHERE r.EVENT_CODE = 100 
GROUP BY 
    r.SEX 
    , r.disc_Code 
order by r.disc_code 

我可以使用一張表,但我還沒有看到任何鏈接在stackoverflow或MSDN中的兩個組表達式的示例。我錯過了一些東西?

回答

1

上,你必須做這樣的事情多標準組:

var query = from book in books 
group book by new {book.author, book.editor} into books; 

訪問它們:

var author = books.Key.author; 
var editor = books.Key.editor; 
2

也許是這樣的:

 var results = from r in dataContext.Race 
         where r.EVENT_CODE == 100 
         orderby r.Disc_Code ascending 
         group r by new { r.Sex, r.Disc_Code } into g 
         select g.Key; 
2

下面是一個例子VB.NET中的grouping by multiple列。

Dim query = From r In db.Race _ 
      Where r.EVENT_CODE = 100 _ 
      Order By r.disc_Code _ 
      Group By Key = New With {r.Sex, r.disc_Code} Into Group _ 
      Select Key, Group