3
votes

I am having trouble getting OData to work with Asp.Net Web Api when the underlying data is NOT coming from Entity Framework.

I am using the latest OData Nuget package (Microsoft ASP.NET Web API OData 0.2.0-alpha release) but when I attempt to pass an OData query (say $top=10) I receive the error:

The given key was not present in the dictionary

If I don't send an OData query I can call the method just fine. The other methods in the same Web Api project that use Entity Framework work fine with OData queries. The one's that don't work are using Subsonic ORM to query an underlying AS400 data source. It returns an IQueryable. This worked just fine before the VS 2012 and .NET 4.5 RTM was released and OData was moved into a separate package. (i.e. worked with beta and RC versions of VS2012 and .NET 4.5)

Any ideas would be appreciated.

1
can you add a stack trace? I'll try to take a look. - Youssef Moussaoui

1 Answers

1
votes

I guess this issue is caused by stable ordering, which doesn't work well with the underlying query provider. Could you put the call stack of the error to confirm it?

One big change with OData query composition in this release is that it ensures stable ordering before taking top items. The reason to do that is user may have random data source which makes return data keep changing.

The way web api odata package does is to add OrderyBy [Keys] query before executing top. Or if there is no key defined in the model (Keys are ID, EntityID, or [Key] attributed property), it will use all the primitive properties in the model to order.

If you can make sure that the data source will always return data with stable ordering, you can turn off this feature by code:

[Queryable(EnsureStableOrdering = false)]