Posted by
Scott
on
2. October 2008 14:18
I needed to get a query completed like this in LINQ.
Select max(uid) as uid, Serial_Number from Table Group BY Serial_Number
I thought about it for a while but didn't get anywhere. I kept testing until I asked another person and they came up with:
using (DataContext dc = new DataContext())
{
var q = from t in dc.TableTests
group t by t.SerialNumber
into g
select new
{
SerialNumber = g.Key,
uid = (from t2 in g select t2.uid).Max()
};
}
This code is very nice and sweet. It allows you to select the all MAX Rows of a table with a grouped table column.
Hope you enjoyed this little lesson. I decided to save this syntact because it is something I will most likely come accross again.
Scott
If you liked this post, please be sure to subscribe to my
RSS Feed.