Linq Order By a subtable
Posted
by Michael
on Stack Overflow
See other posts from Stack Overflow
or by Michael
Published on 2010-04-16T09:23:31Z
Indexed on
2010/04/16
9:33 UTC
Read the original article
Hit count: 176
Hello,
My question is how to sort a Linq query by a sub table:
Table Apps:
- app_id
- name
Table AppStatus:
- app_status_id
- app_id
- severity
- status_date
I would like to have a query with all the apps, sorted by the last status severity:
app_id name
1 first
2 second
3 third
app_status_id app_id severity status_date
1 1 5 12-4-2010
2 1 2 15-4-2010
3 2 7 10-4-2010
4 3 3 13-4-2010
Now i want it sorted like:
app_id name
3 third
1 first
2 second
Can anyone help me with a LINQ query for this.
I tried the following already, but that didn't work:
var apps = from apps in dc.Apps
orderby apps.AppStatus.LastOrDefault().severity
select apps;
© Stack Overflow or respective owner