我正在使用 WebAPI 从 RavenDb 返回基本供应商对象的集合
供应商类是:
public class Supplier
{
public string Id { get; set; }
public string Title { get; set; }
}
WebAPI 方法是:
[Queryable]
public IQueryable<Supplier> Get()
{
using (var session = _store.OpenSession())
{
return session.Query<Supplier>();
}
}
当我打电话http://localhost:8083/api/suppliers?$orderby=Id%20desc
或http://localhost:8083/api/suppliers?$filter=Title%20eq%20'Test'
一切正常。但是,每当我使用 $top 或 $skip 时,都会出现异常:
无法将“System.Linq.Expressions.PropertyExpression”类型的对象转换为“System.Linq.Expressions.ConstantExpression”类型。
如果我使用 ToList() 将整个集合返回到内存中,它可以正常工作,因此它看起来像是使用 RavenDb 延迟执行查询的问题。
我正在使用 RavenDb.Client 2.0.2.2261 的最新稳定版本。
有没有其他人遇到过这个问题或有解决方案?
堆栈跟踪是:
at Raven.Client.Linq.RavenQueryProviderProcessor`1.VisitQueryableMethodCall(MethodCallExpression expression) in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Linq\RavenQueryProviderProcessor.cs:line 994
at Raven.Client.Linq.RavenQueryProviderProcessor`1.VisitMethodCall(MethodCallExpression expression, Boolean negated) in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Linq\RavenQueryProviderProcessor.cs:line 693
at Raven.Client.Linq.RavenQueryProviderProcessor`1.VisitExpression(Expression expression) in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Linq\RavenQueryProviderProcessor.cs:line 140
at Raven.Client.Linq.RavenQueryProviderProcessor`1.GetLuceneQueryFor(Expression expression) in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Linq\RavenQueryProviderProcessor.cs:line 1318
at Raven.Client.Linq.RavenQueryProviderProcessor`1.Execute(Expression expression) in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Linq\RavenQueryProviderProcessor.cs:line 1352
at Raven.Client.Linq.RavenQueryProvider`1.Execute(Expression expression) in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Linq\RavenQueryProvider.cs:line 135
at Raven.Client.Linq.RavenQueryProvider`1.System.Linq.IQueryProvider.Execute(Expression expression) in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Linq\RavenQueryProvider.cs:line 190
at Raven.Client.Linq.RavenQueryInspector`1.GetEnumerator() in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Linq\RavenQueryInspector.cs:line 99
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Newtonsoft.Json.Serialization.JsonArrayContract.CreateWrapper(Object list)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value)
at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value)
at Newtonsoft.Json.JsonSerializer.Serialize(JsonWriter jsonWriter, Object value)
at System.Net.Http.Formatting.JsonMediaTypeFormatter.<>c__DisplayClassd.<WriteToStreamAsync>b__c()
at System.Threading.Tasks.TaskHelpers.RunSynchronously(Action action, CancellationToken token)