开发者

Linq Query Distinct by Name Distinct Throwing Exception

开发者 https://www.devze.com 2023-01-19 02:54 出处:网络
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

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

精彩评论

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