我正在使用Linq to Entities并收到此错误
The method Distinct is not supported
在这行代码上
var typeIds = _context.AttributeValues.Select(av => av.AttributeTypeId).Distinct();
为什么会这样?
答案 0 :(得分:1)
根据MSDN,不支持使用OData服务的LINQ方法。以下是不支持的方法的部分列表。
有关不受支持的操作的完整列表,请参阅here
但是,在这种情况下,解决方法后面的语句应该有效。
var typeIds = _context.AttributeValues
.Select(av => av.AttributeTypeId)
.AsEnumerable()
.Distinct();
答案 1 :(得分:0)
解决方案是使用(服务器端)我的产品AdaptiveLINQ(www.adaptivelinq.com)提供的QueryByCube
方法定义WCF数据服务。 此方法转换聚合中的投影(由选择运算符表示)。
您只需要定义一个具有一个维度的多维数据集:AttributeTypeId
av => av.AttributeTypeId
定义提供可查询集合的数据服务:
yourDbContext.AttributeValues.QueryByCube(yourCube);
现在您可以使用OData协议查询您的服务:
http://.../myService.svc/AttributeValues?$select=AttributeTypeId
或者,如果您使用的是C#客户端:
serviceContext.AttributeValues.Select(x => x.AttributeTypeId);
此解决方案相对于提议的解决方案的优势A J Qarshi是区分在服务器端。