简体   繁体   中英

Retrieve Distinct Records in LINQ Query

I have a DataSet and Select few records from Table in DataSet using following query:

EnumerableRowCollection<DataRow> GenresQuery = from genre in Books.AsEnumerable() where genre.Field<string>("genre") == strGenresSelectionParameter select genre;

It is working fine but, I want to select distinct records. How it can be done ?

Use Distinct

IEnumerable<DataRow> GenresQuery = (from genre in Books.AsEnumerable()
                                    where genre.Field<string>("genre") == strGenresSelectionParameter 
                                    select genre).Distinct();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM