Sunday, March 28, 2010

Using LINQ to query dataset for Distinct

I just wanted to query (quickly) a dataset to get a distinct pair of values.
Heres a quick way of doing it

var distinctValues = (from row in dataSet.Tables[0].AsEnumerable()
select new
{
SomeColumn1 = row["SomeColumn1"],
SomeColumn2 = row["SomeColumn2"]
}).Distinct().OrderBy(o=>o.SomeSolumn1).ToArray();

No comments:

Post a Comment