In LINQ
if the result that I have is the a list of whole records from the database and I want to do a Distinct
on one column of this record, How do I do that?
Asked
Active
Viewed 116 times
1 Answers
0
You could try something as simple as:
var distincts = records.Select(x=>x.ColumnName).Distinct();

Christos
- 53,228
- 8
- 76
- 108
-
I still want the whole record after selecting distinct ones based on that column, does it return the whole records ? – Bohn Jun 16 '15 at 19:57
-
1The above query initially projects each record to the value of the `ColumnName` and then returns the distinct values. So, no it doesn;t return the whole records. Furthermore, that you are looking for without making any other assumptions is impossible. For instance, let that we have two records with the same value for `ColumnName`, which one of the two we should pick? One option it would be to group them bu the `ColumnName` and take the first record of each group but honestly I don't if that's you are looking for. – Christos Jun 16 '15 at 20:01