开发者

Linq Query Distinct by Name Distinct Throwing Exception

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 开发者_Go百科to get the Count of each Attribute grouped by "Attribute" value where Attribute is a property on NounTypeAttributes table.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜