2009-05-19 74 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