2013-03-10 24 views
5

Tôi đang sử dụng WebAPI để trả về một bộ sưu tập của các đối tượng nhà cung cấp cơ bản từ RavenDb

Lớp Nhà cung cấp là:

public class Supplier 
{ 
    public string Id { get; set; } 
    public string Title { get; set; } 
} 

Các WebAPI phương pháp là:

[Queryable] 
public IQueryable<Supplier> Get() 
{ 
    using (var session = _store.OpenSession()) 
    { 
     return session.Query<Supplier>(); 
    } 
} 

Khi tôi gọi http://localhost:8083/api/suppliers?$orderby=Id%20desc hoặc http://localhost:8083/api/suppliers?$filter=Title%20eq%20'Test' tất cả mọi thứ hoạt động tốt. Tuy nhiên, bất cứ khi nào tôi sử dụng $ đầu hoặc $ bỏ qua, tôi đều nhận được ngoại lệ:

Không thể truyền đối tượng thuộc loại 'System.Linq.Expressions.PropertyExpression' vào loại 'System.Linq.Expressions.ConstantExpression'.

Nếu tôi trả lại toàn bộ bộ sưu tập vào bộ nhớ bằng ToList() nó hoạt động tốt, vì vậy có vẻ như vấn đề với việc thực hiện truy vấn trì hoãn với RavenDb.

Tôi đang sử dụng bản phát hành ổn định mới nhất của RavenDb.Client 2.0.2.2261.

Có ai khác có vấn đề này hoặc có giải pháp cho nó không?

Các Stack Trace là:

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) 
+0

Bạn có thể chia sẻ theo dõi ngăn xếp không? –

+0

Tôi đã thêm dấu vết ngăn xếp vào câu hỏi – valps

Trả lời

9

tôi đã có thể repro vấn đề của bạn và đã thành công có thể xác nhận đoán ban đầu của tôi về những gì có thể đi sai. Hãy thử [Queryable(EnableConstantParameterization = false)] thay vì đồng bằng [Queryable]. Cuối chu kỳ phát triển OData, chúng tôi đã thực hiện thay đổi hoàn hảo để sử dụng tối ưu EF automatic compilation of LINQ queries. Chúng tôi cho phép nó theo mặc định vì đây là một thay đổi an toàn. Thật không may, tôi nghĩ rằng nhà cung cấp LINQ RavenDB không thể hiểu được các truy vấn LINQ được tạo ra với tối ưu hóa này. Mã mà tôi đã chia sẻ sẽ tắt và tạo các truy vấn LINQ vani.

+1

Bắt tốt. Ngoài ra, bạn có thể muốn đặt 'HandleNullPropagation' sai. Xem [chủ đề này] (https://groups.google.com/d/msg/ravendb/o2kbCy57Yqs/rUAmxaILanMJ) –

Các vấn đề liên quan