如何使用 OData 和 LINQ 进行嵌套计数?
这是我尝试从 OData 源运行的查询:
var query = from j in _auditService.AuditJobs.IncludeTotalCount()
orderby j.Description
select new
{
JobId = j.ID,
Description = j.Description,
SubscriberCount = j.JobRuns.Count()
};
如果我不使用 j.JobRuns.Count(),它运行得很好,但如果我包含它,我会收到以下错误:
构造或初始化实例 类型的 <>f__AnonymousType1`3[System.Int32,System.String,System.Int32] 使用表达式 j.JobRuns.Count() 不支持。
尝试通过OData获取嵌套计数似乎是一个问题。有什么解决办法吗?我试图避免仅仅为了获得计数而获取每个对象的整个嵌套集合。
谢谢!
Here is the query I am trying to run from my OData source:
var query = from j in _auditService.AuditJobs.IncludeTotalCount()
orderby j.Description
select new
{
JobId = j.ID,
Description = j.Description,
SubscriberCount = j.JobRuns.Count()
};
It runs great if I don't use the j.JobRuns.Count(), but if I include it I get the following error:
Constructing or initializing instances
of the type
<>f__AnonymousType1`3[System.Int32,System.String,System.Int32]
with the expression j.JobRuns.Count()
is not supported.
It seems to be a problem of attempting to get the nested count through OData. What is a work around for this? I was trying to avoid getting the whole nested collection for each object just to get a count.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
截至目前,OData 协议不支持聚合。
预测是的,但包含聚合属性的预测则不是。
亚历克斯
As of today the OData protocol doesn't support aggregates.
Projections yes, but projections that include aggregate properties no.
Alex
您需要 .Net 4.0 并且在 LinqPad 中您可以通过 netflix OData 服务运行以下命令
You need .Net 4.0 and In LinqPad you can run following over netflix OData Service
您现在可以使用我的产品 AdaptiveLINQ 和扩展方法
QueryByCube
。You can now use my product AdaptiveLINQ and the extension method
QueryByCube
.