不支持MongoDB方法

时间:2017-01-25 05:44:09

标签: mongodb

我有一个复杂的查询,其中我将从多个公司的表中提取文章,然后按公司ID分组,然后根据lastupdated / published date订购每个组,然后按公司/组排名前2。 显然,它是抛出错误,我不想使用asenumerable(),因为它是一个非常大的表,我不希望数据加载到内存中。 这是查询:

var articles = (from article in collection.AsQueryable()
                                    where companyIds.Contains(article.CompanyId)
                                    where article.Active
                                    group article by article.CompanyId
                            into companyArticles
                                    select (from a in companyArticles
                                            orderby a.PublicationDate descending
                                            select a).Take((int) maxPerCompany)
                            ).SelectMany(a => a)
                            .OrderByDescending(a => a.PublicationDate)
                            .Skip(checked((int) skip))
                            .Take(checked((int) length))
                            .ToList();


//或linq

var companiesArticles = collection.AsQueryable()
                            .Where(c => companyIds.Contains(c.CompanyId) && c.Active)
                            .GroupBy(a => a.CompanyId, (a, records) =>
                                records.OrderByDescending(a => a.PublicationDate).Take((int) maxPerCompany))
                            .SelectMany(a => a)
                            .OrderByDescending(a => a.PublicationDate)
                            .Skip(checked((int) skip))
                            .Take(checked((int) length))
                            .ToList();

非常感谢任何帮助。

异常消息: 表达式树不支持OrderByDescending方法:{document} .OrderByDescending(a => a.PublicationDate)。

异常堆栈跟踪:    在MongoDB.Driver.Linq.Processors.PipelineBinderBase 1.BindMethodCall(MethodCallExpression node) at MongoDB.Driver.Linq.Processors.PipelineBinderBase 1.Bind(表达式节点)    在MongoDB.Driver.Linq.Processors.PipelineBinderBase 1.BindPipeline(Expression node) at MongoDB.Driver.Linq.Processors.PipelineBinderBase 1.BindMethodCall(MethodCallExpression节点)    在MongoDB.Driver.Linq.Processors.PipelineBinderBase 1.Bind(Expression node) at MongoDB.Driver.Linq.Processors.EmbeddedPipeline.EmbeddedPipelineBinder.Bind(Expression node, IBindingContext parent) at MongoDB.Driver.Linq.Processors.SerializationBinder.BindEmbeddedPipeline(MethodCallExpression node) at MongoDB.Driver.Linq.Processors.SerializationBinder.VisitMethodCall(MethodCallExpression node) at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor) at MongoDB.Driver.Linq.Processors.SerializationBinder.Visit(Expression node) at MongoDB.Driver.Linq.Processors.Pipeline.MethodCallBinders.SelectBinder.Bind(PipelineExpression pipeline, PipelineBindingContext bindingContext, MethodCallExpression node, IEnumerable 1个参数)    在MongoDB.Driver.Linq.Processors.MethodInfoMethodCallBinder 1.Bind(PipelineExpression pipeline, TBindingContext bindingContext, MethodCallExpression node, IEnumerable 1个参数)    在MongoDB.Driver.Linq.Processors.PipelineBinderBase 1.BindMethodCall(MethodCallExpression node) at MongoDB.Driver.Linq.Processors.PipelineBinderBase 1.Bind(表达式节点)    在MongoDB.Driver.Linq.Processors.PipelineBinderBase 1.BindPipeline(Expression node) at MongoDB.Driver.Linq.Processors.PipelineBinderBase 1.BindMethodCall(MethodCallExpression节点)    在MongoDB.Driver.Linq.Processors.PipelineBinderBase 1.Bind(Expression node) at MongoDB.Driver.Linq.Processors.PipelineBinderBase 1.BindPipeline(表达式节点)    在MongoDB.Driver.Linq.Processors.PipelineBinderBase 1.BindMethodCall(MethodCallExpression node) at MongoDB.Driver.Linq.Processors.PipelineBinderBase 1.Bind(表达式节点)    在MongoDB.Driver.Linq.Processors.PipelineBinderBase 1.BindPipeline(Expression node) at MongoDB.Driver.Linq.Processors.PipelineBinderBase 1.BindMethodCall(MethodCallExpression节点)    在MongoDB.Driver.Linq.Processors.PipelineBinderBase 1.Bind(Expression node) at MongoDB.Driver.Linq.Processors.PipelineBinderBase 1.BindPipeline(表达式节点)    在MongoDB.Driver.Linq.Processors.PipelineBinderBase 1.BindMethodCall(MethodCallExpression node) at MongoDB.Driver.Linq.Processors.PipelineBinderBase 1.Bind(表达式节点)    在MongoDB.Driver.Linq.Processors.Pipeline.PipelineBinder.Bind(Expression node,IBsonSerializerRegistry serializerRegistry)    在MongoDB.Driver.Linq.MongoQueryProviderImpl 1.Prepare(Expression expression) at MongoDB.Driver.Linq.MongoQueryProviderImpl 1.Translate(表达式表达式)    在MongoDB.Driver.Linq.MongoQueryProviderImpl 1.Execute(Expression expression) at MongoDB.Driver.Linq.MongoQueryableImpl 2.GetEnumerator()    在System.Collections.Generic.List 1..ctor(IEnumerable 1个集合)    在System.Linq.Enumerable.ToList [TSource](IEnumerable`1 source)    在

0 个答案:

没有答案