Linq Order By a subtable
- by Michael
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;