views:

236

answers:

3

Hi guys! I am having a real pain in converting this query expression into my LINQ expression.

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

i can work with one table but i have not seen any example which chains two group expressions in stackoverflow or MSDN. Am i missing some thing ?

+1  A: 

to group on multiple criteria you have to do something like this:

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

to access them:

var author = books.Key.author;
var editor = books.Key.editor;
CSharpAtl
+2  A: 

Maybe something like this:

        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;
bruno conde
+2  A: 

Here's an example of grouping by multiple columns in VB.NET.

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
Jose Basilio