I have this query:
from i in dc.TFFiles
where i.Tid == tid
group i by new { i.Title, i.Type } into gr
select gr.OrderByDescending(g => g.Version).First();
I want to add a join with another table so I will have access to a field of the second table
Here is the join I need without the group by
:
from i in dc.TFFiles
join c in dc.FCategory on i.CatId equals c.id
....
How I can combine the group by
query with the join
Tried like this but it doesn't order the results by Version descending. I always get Version 1 even though there are files with higher versions.
var result =
from i in dc.TFFiles
where i.Tid == tid
group i by new { i.Title, i.Type } into gr
orderby gr.FirstOrDefault().Version descending
join c in dc.FCategories on gr.FirstOrDefault().CatId equals c.Id
select new { id = gr.FirstOrDefault().id, Title = gr.FirstOrDefault().Title, Version = gr.FirstOrDefault().Version };