Monday, August 29, 2011

How to implement SQL Distinct keyword in LINQ?

There is a Distinct keyword in LINQ, but not as same as in SQL.
Following is the same implementation for SQL distinct in LINQ

    var distinctItems = items
       .GroupBy(x => x.PropertyToCompare)
       .Select(x => x.First());


No comments:

Post a Comment