0

Possible Duplicate:
LINQ select distinct c#

I'm trying to do something like this:

List<string> manufacturerFilters = new List<string>(){"Honda", "Ford", "Jaguar", "BMW"};
var products = (from p in context.Products
                where p.DeletedSince.Equals(null)
                && manufacturerFilters.Contains(p.Manufacturer.Name)
                && p.SomeValue == 123).Distinct(**p.Manufacturer**).Take(4);

Now this gives me a list of products that belong to the 4 manufacturers in my filter list. But what i really want, is 4 products, 1 from each manufacturer. That is why i put this Distinct in my query, which of course, is not working..

How should i do this type of distinct query?

Community
  • 1
  • 1
Tys
  • 3,592
  • 9
  • 49
  • 71
  • 1
    You may want to try `DistinctBy` of [morelinq](http://code.google.com/p/morelinq/) – L.B Jul 28 '12 at 16:33

1 Answers1

0
.Distinct(**p.Manufacturer.Name**) 

p.Manufacturer is of reference type and hence it take all as distinct because they have different refernces.I hope this will help. If you want .Distinct(p.Manufacturer) to work then you will have to specify Comparer.

yo chauhan
  • 12,079
  • 4
  • 39
  • 58