我很难将这个查询表达式转换为我的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中的两个组表达式的示例。我错过了什么吗?
答案 0 :(得分: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;
答案 1 :(得分: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
答案 2 :(得分: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;