Linq query with aggregate function OrderBy
Posted
by Billy Logan
on Stack Overflow
See other posts from Stack Overflow
or by Billy Logan
Published on 2010-05-29T18:32:16Z
Indexed on
2010/05/29
18:42 UTC
Read the original article
Hit count: 484
linq-to-entities
Hello everyone, I have the following LinqToEntities query, but am unsure of where or how to add the orderby clause:
var results =
from d in db.TBLDESIGNER
join s in db.TBLDESIGN on d.ID equals s.TBLDESIGNER.ID
where s.COMPLETED && d.ACTIVE
let value = new { s, d}
let key = new { d.ID, d.FIRST_NAME, d.LAST_NAME }
group value by key into g
orderby g.Key.FIRST_NAME ascending, g.Key.LAST_NAME ascending
select new
{
ID = g.Key.ID,
FirstName = g.Key.FIRST_NAME,
LastName = g.Key.LAST_NAME,
Count = g.Count()
};
This should be sorted by First_Name ascending and then Last_Name ascending.
I have tried adding ordering but It has had no effect on the result set. Could someone please provide an example of where the orderby would go assuming the query above. Thanks, Billy
© Stack Overflow or respective owner