-
Notifications
You must be signed in to change notification settings - Fork 475
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
$filter doesnt work with Enums type - dotnet core beta1 #1186
Comments
@robward-ms: netstandard1.1 is mentioned above. Should it be supported? |
@biaol-odata - Yes, netstandard 1.1 for a model class should be fine. @HaroonSaid - There is an unresolved issue that does not get hit in the UT or E2E tests but the assembly resolver is not fully implemented in a few cases, this appears to have hit that. Can you provide the full callstack? |
The call stack
|
Have the same issue. Would be nice to have support of Enums in filters |
Is somebody able to provide a hotfix of some sort? |
I attempted a repo today and did not get this callstack. I did merge with master recently but I'm unsure how that has impacted the issue. I was able to get the scenario working. However, it involved using the StringAsEnumResolver for which we have little documentation. There is a SO discussion here: https://stackoverflow.com/questions/40997153/how-to-enablecaseinsensitive-enableenumprefixfree-and-enableunqualifiednamecall The change I made as applied to your sample looks like: original: routes.MapODataServiceRoute("odata", "api", ODataConfig.GetEdmModel(app.ApplicationServices)); new: routes.MapODataServiceRoute("odata", "api", builder => Once the StringAsEnumResolver was added the config, I was able to filter by enum using: http://localhost:5000/api/projects?$filter=Status eq 'Active' Can one of you try this configuration? |
#1231 filed for documenting how to configure prefix-free enums. |
Thanks - I will give it a try and let you know the results.
…On Mon, Feb 5, 2018 at 3:33 PM, Rob Ward ***@***.***> wrote:
I attempted a repo today and did not get this callstack. I did merge with
master recently but I'm unsure how that has impacted the issue.
I was able to get the scenario working. However, it involved using the
StringAsEnumResolver for which we have little documentation. There is a SO
discussion here: https://stackoverflow.com/questions/40997153/how-to-
enablecaseinsensitive-enableenumprefixfree-and-enableunqualifiednamecall
The change I made as applied to your sample looks like:
original: routes.MapODataServiceRoute("odata", "api",
ODataConfig.GetEdmModel(app.ApplicationServices));
new: routes.MapODataServiceRoute("odata", "api", builder =>
builder.AddService(Microsoft.OData.ServiceLifetime.Singleton, sp =>
edmModel)
.AddService<IEnumerable>(Microsoft.OData.ServiceLifetime.Singleton, sp =>
ODataRoutingConventions.CreateDefaultWithAttributeRouting("OData",
routes))
.AddService(Microsoft.OData.ServiceLifetime.Singleton, sp => new
StringAsEnumResolver()));
Once the StringAsEnumResolver was added the config, I was able to filter
by enum using:
http://localhost:5000/api/projects?$filter=Status eq 'Active'
Can one of you try this configuration?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1186 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ACE5ZKdszIEI7tXCAWpHVotKg3VbVCioks5tR4-_gaJpZM4RPe4B>
.
--
Haroon Said
|
@robward-ms - Hi Rob, I tried your suggestions, but I still can't couldn't get the code to work.
The error that I keep getting is, different then before.
I have a 'UnqualifiedCallAndEnumPrefixFreeResolver class' that I want to injected. The code is as follows:
What am I doing wrong? |
I'm also having this problem with .net core beta1, trying to get enums to work in the $filter clause, even when fully qualifying the enum name I get the same error: System.NotImplementedException: The method or operation is not implemented. Is it correct to say that with the current beta, enums are not supported in filters? |
The merge with master, which was only available in the nightly builds, may have an impact here. Can you try it with the just-released Beta 2? |
Exception changed in comparision to beta1 - but still not working with beta2. status eq 'Finished' Status eq '2' status eq 2 |
Ok, got it working now - at least with Strings adding the following to Startup: |
Confirming the issue and the fix with StringAsEnumResolver approach that works. Thanks for hinting. EDIT: tested with: 7.0.0-Nightly201803071313 |
@HaroonSaid - The merge with master, which was only available in the nightly builds, may have an impact here. Can you try it with the just-released Beta 2? |
Confirming the issue and the fix with StringAsEnumResolver approach that works tested with Beta 2. |
I will give it a try and let you know. Thanks for the update. |
Looks like StringAsEnumResolver is fixed with Beta 2 |
@DJHightower I've tried Your solution with beta 2 and I still get this error:
My Startup class looks like this:
Any hints are more than welcome. |
Can you show me your class "Product" and the enum "CoreTest1.Models.Category" and the URL resulting in this exception pls? |
@DJHightower I've created new project in VS 2017, added those classes:
and this as a controller:
I'm calling this url: http://localhost:62439/odata/Products?$filter=Category%20eq%20%27Cars%27 In Chrome Dev Tools I can see that Query String Parameters are:
but I get this as a response:
|
Cant tell why your version is not working - it looks like it should - but: if you change your controller to look like:
and use the URL given as Attribute, it works. Maybe you like to experiment from that point. |
@DJHightower thanks for looking into this. |
The code is on the right place in your sample. Just looks like the StringAsEnumResolver is ignored in your odata-Route. But it seems to be correctly handled if the route is given in the controller as a class-attribute ("api/Products" in my sample). |
@Misiu - Can you post a sample project that shows the issue to github? |
@robward-ms not so good with git, but I think all files are included: https://github.com/Misiu/ODataNetCoreTests |
@Misiu - Project looks good and compiles, thanks. Can you tell me which Uri you are using for the test? |
@robward-ms I'm trying to get products in specific category - http://localhost:62439/odata/Products?$filter=Category%20eq%20%27Cars%27 In Dev Tools in Chrome I see thisQuery String Parameters:
but I get error instead of data. |
@Misiu - Drop the following code in your Configure method. Here are the key differences: 1.) With the EnableDependencyInjection method, you were inserting a StringAsEnumResolver on the default (non-OData) route. You want one on the OData route instead.
|
@robward-ms Thank You, not it works great :) It would be awesome to have this as part of README - would make life easier. P.S. Can this be combined with case insensitive routes? Those two don't: First one gives me:
second gives not found. I've tried adding another service |
#1231 filed for documenting how to configure prefix-free enums. Take a look at UnqualifiedCallAndEnumPrefixFreeResolver.cs. I think we only support a single ODataUriResolver so adding two won't perform as expected. |
@robward-ms I've replaced but I get errors when accessing lowercase url's. I can access standard API controllers via I've searched over the internet and I only found case insensitive filters, but nothing about case insensitive routes and properties names for odata. |
We have some tests that fails on syntax as follows, what do we need to do to make Enums work
http://localhost:5000/api/projects?$filter=Status eq 'Active'
http://localhost:5000/api/projects?$filter=Status eq 1
The Errors are:
"error": "The method or operation is not implemented."
or
A binary operator with incompatible types was detected. Found operand types 'Bluebeam.SecurityCore.Enum.Status' and 'Edm.Int32' for operator kind 'Equal'."
}
The bugs seems to be in the method when a Filter is a constant and code needs to look thru all the assemblies
The config is as follows:
The model looks as follows
and Status is, the Enum is in a different assembly (netstandard1.1) project
The controller is:
The exception seems to be occurring on the following lines of code:
The text was updated successfully, but these errors were encountered: