-
Notifications
You must be signed in to change notification settings - Fork 709
OData queries don't work #525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Did that also require you to update the version of the OData library you've been using? There are a number of behavioral, breaking changes between major versions. You might need to share more about one of your controller setups. I was able to take the basic OData example for Web API and have
Queries definitely work, but I'll need some more information about your configuration to help you get things working. |
I'm using latest versions of NuGet libraries:
|
full WebApiConfig.cs:
|
ObjectController.cs:
|
exception info: |
Спасибо In short, OData 7.2 introduces a behavioral change that breaks API Versioning. This is because OData changed the service collection - again. You can see this in ContainerBuilderExtensions.AddDefaultWebApiServices. Specifically, the SkipTokenHandler and SkipTokenQueryValidator are new types that are registered in the container. Unfortunately this method is internal 😒 and it didn't seem like the default services would change. This resulted in replicating the registration in API versioning, but now there is a breaking change. It seems I'll have to go back to resorting to Reflection in order to call the internal method to prevent this from happening again. 😣 The fix isn't terribly difficult. I should be able to get it out by tomorrow. In the meantime, you can either wait or go back to a version < 7.2.0. The sample project targets 7.0.1 and it definitely works. Извините за это. Спасибо за ваше терпение |
With Microsoft.AspNet.OData 7.1.0 it works fine. Thank you! |
No problem. I also realized that the issue is just missing service registrations. This means that you should be able to make 7.2.0 work if you really want to by adding the following container builder configurations to the callback registered in MapVersionedODataRoutes: builder.AddService<SkipTokenQueryValidator>(ServiceLifetime.Singleton);
builder.AddService<SkipTokenHandler, DefaultSkipTokenHandler>(ServiceLifetime.Singleton); This missing registeration is the cause of the exception. Regardless, I'll be making the fix as this is a landmine waiting for others to step on. Thanks. |
FYI ... the patch for this has been published. |
I have added a versioning in WebApi project. If I use OData queries such like this:
/api/v1/Object?$skip=1
the status 500 is returned with message:
In WebApiConfig.cs I have added the following code:
config.AddApiVersioning();
builder = new VersionedODataModelBuilder(config)
{
ModelConfigurations = { new ObjectModelConfiguration() }
};
config.MapVersionedODataRoutes("odata", "api/v{apiVersion}", builder.GetEdmModels());
Before adding Microsoft.AspNet.OData.Versioning OData queries were working.
The text was updated successfully, but these errors were encountered: