Amanda Kitson
Amanda Kitson

Reputation: 5547

Having trouble getting an SQL query converted to Linq to Entities

I have the following SQL query:

SELECT Comment, JD, Jurisdiction, RegStatus, Region, SPDR_NAME 
FROM dbo.Registered_status_by_year 
GROUP BY Comment, JD, SPDR_NAME, Region, Jurisdiction, RegStatus 
HAVING (Region = @Region) ORDER BY JD

I am trying to convert it to linq to entities. I have the following, so far:

var result = (from x in myEntities.IRTStatusByYearSet
                          group x by new { x.Comment, x.JD, x.SPDR_NAME, x.Region, x.Jurisdiction, x.RegStatus } into g
                          select g);

The problem is that I can't seem to use the "orderby" because "g" doesn't have any "properties" that are the column names.

Does anyone know how I might do this? I have looked for examples of doing the order by with grouping, but all of them show only grouping by one thing, or ordering by the "count" of items in grouping, instead of by some other value.

Upvotes: 1

Views: 157

Answers (1)

Aducci
Aducci

Reputation: 26694

Have you tried orderby g.Key.JD?

var result = (from x in myEntities.IRTStatusByYearSet
              group x by new { x.Comment, x.JD, x.SPDR_NAME, x.Region, x.Jurisdiction, x.RegStatus } into g
              orderby g.Key.JD
              select g);

Upvotes: 2

Related Questions