不支持Distinct方法 [英] The method Distinct is not supported
问题描述
我正在使用Linq to Entities,并且收到此错误
I am using Linq to Entities and am getting this error
The method Distinct is not supported
在这一行代码
var typeIds = _context.AttributeValues.Select(av => av.AttributeTypeId).Distinct();
为什么是这样?
推荐答案
解决方案是使用(服务器端)由我的产品AdaptiveLINQ( QueryByCube 方法定义WCF数据服务http://www.adaptivelinq.comrel =nofollow> www.adaptivelinq.com )。 此方法在聚合
A solution is to define a WCF Data Service using (server-side) the QueryByCube
method provided by my product AdaptiveLINQ (www.adaptivelinq.com). This method transforms a projection (expressed by the select operator) in an aggregation.
您只需定义具有一个维度的多维数据集:AttributeTypeId
You have just to define a cube with one dimension : AttributeTypeId
av => av.AttributeTypeId
定义提供可查询集合的数据服务:
Define a Data Service providing the queryable collection:
yourDbContext.AttributeValues.QueryByCube(yourCube);
现在您可以使用OData协议查询您的服务:
Now you can query your service using the OData protocol:
http://.../myService.svc/AttributeValues?$select=AttributeTypeId
或者,如果您使用C#客户端:
Or, if your using a C# client:
serviceContext.AttributeValues.Select(x => x.AttributeTypeId);
此解决方案相对于解决方案的优势提出,AJ Qarshi认为,在服务器端。
The advantage of this solution relative to the workaround proposed A J Qarshi is that the distinction is made on the server side.
这篇关于不支持Distinct方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!