Distinct is not working for table records

Jun 26, 2011 at 9:36 AM
Edited Jun 26, 2011 at 9:37 AM

Hi, I am trying to get unique value types from table, but it's always returning all records.

For below EF query, I am always seeing duplicate values. Am I doing anything wrong? Appreciate all of your sugessitions.

IEnumerable<Shop> shops = from item in

 ShopItemList  

 select item.Shop;

 return 

shops.Distinct(); 



Thanks

Rosi Reddy

 

 

Coordinator
Jun 27, 2011 at 10:37 PM

Sterling has nothing to do with whether or not an item is "distinct" or not. It simply returns a list and allows LINQ to Objects to take over. If you are having issues, make sure you are properly impementing Equals and GetHashCode to ensure that LINQ knows what "distinct" means for your class.