Nagarajan Venu
Pages
Home
About Me
Disclaimer
Tuesday, November 9, 2010
Distinct list with class property in Linq
In some scenario you may need to group by one of the property in collection so there is no direct way to group but we can use this query
lstTempOutlet = lstOutlets.
GroupBy
(o =>o.propertyname).
Select
(o => o.
First
()).ToList<>();
In case to multiple properties
lstTempOutlet = lstOutlets.
GroupBy
(o =>
new
{o.propertyname1, o.propertyname2, o.propertyname3 , etc.,}).
Select
(o => o.
First
()).ToList<>();
No comments:
Post a Comment
Newer Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment