tags:

views:

55

answers:

1

I have a simple query where I want to get the attributes distinct using the value stored in the "Attribute" property. For some reason I always get Distinct operation not supported for this overload error.

var nounTypes = from c in query
                                join cna in ics.CatalogNounAttributes on c.CatalogId equals cna.CatalogId
                                join nta in ics.NounTypeAttributes on cna.NounTypeAttributeId equals nta.NounTypeAttributeId
                                join nt in ics.NounTypes on nta.NounTypeId equals nt.NounTypeId
                                select new { NounTypeName = nt.Name, Attributes = nt.NounTypeAttributes.Distinct() };

I would also like to get the Count of each Attribute grouped by "Attribute" value where Attribute is a property on NounTypeAttributes table.

+2  A: 

I believe you should simply say nt.Distinct.

var nounTypes = from c in query
                                join cna in ics.CatalogNounAttributes on c.CatalogId equals cna.CatalogId
                                join nta in ics.NounTypeAttributes on cna.NounTypeAttributeId equals nta.NounTypeAttributeId
                                join nt in ics.NounTypes on nta.NounTypeId equals nt.NounTypeId
                                select new { NounTypeName = nt.Name, Attributes = nt.Distinct() };

You do not need to use the Distinct.

Take a look at :

http://msdn.microsoft.com/en-us/vcsharp/aa336761.aspx#distinct2

Michael Eakins
Thanks I used GroupBy and Select to make a distinct functionality.
john doe
Awesome, good thinking.
Michael Eakins