Consider a table with the following schema
I would like to fetch data from each Status where category is max
- In '1' Status, max category is 2, so fetch all rows of category 2
- In '2' Status, max category is null, so fetch all rows of category null
I need help in creating a linq query to fetch the above data.
I tried a few ways but couldnt get what I wanted. Below is one of the example.
var tableData = (from d in x.Data
group d by d.Status into grp
select new { Status = grp.Key, Category = grp.Max(d => d.Category) }).ToList();
You're close, your current code selects all the statues & their max categories. Now you just need to rejoin on that