tags:

views:

71

answers:

1

How can I return all the columns of a table using multiple distinct columns in linq. I need to return all columns of a table with multiple distincts?

Thanks

+1  A: 

You want to use GroupBy:

var distinctModelYears = cars.GroupBy(c => new { c.Year, c.Model })
                             .Select(g => g.First()) //Take one from each group
                             ;

That will find all "distinct" years and models so there will only be one 2008 Accord, one 2009 Accord, etc.

ifwdev
Taking the above example, say I have columns like Year, Model and Make. I need to return all the columns (Year, Model and Make) Group by Year and Model. So, combination of Year and Model will be unique.
Mohit