Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shortening or omitting namespace for enum in OData filter

Tags:

c#

odata

I took a look at [Tutorial & Sample] Use Enumeration types in OData to see how I could filter data returned by OData using an enumeration. The data model I'm using has a long namespace, and it would be nice to be able to use something shorter, rather than

Organization.Office.Project.DomainObjects.Enumerations.MyEnumeration'MyValue'

it'd be nice to be able to just to do MyEnumeration'MyValue'. How can I do this? I tried setting the Namespace property of the ODataConventionModelBuilder, but it had no effect.

like image 675
Don 01001100 Avatar asked Nov 16 '25 23:11

Don 01001100


1 Answers

Web API OData supports the enum prefix free. I think that's you're looking for.

With enum prefix free enabled, you can directly use the enum value, for example, 'MyValue'

Below is the sample codes how to enable the enum prefix free. http://odata.github.io/WebApi/#06-01-custom-url-parsing

Below's the corresponding end to end test cases provided by OData team:

https://github.com/OData/WebApi/blob/master/OData/test/E2ETest/WebStack.QA.Test.OData/UriParserExtension/EnumPrefixFreeTest.cs

Below is the more detail introduction about the Uri parser extension. http://blogs.msdn.com/b/odatateam/archive/2014/09/12/tutorial-amp-sample-odatauriparser-extension-support.aspx

Thanks

like image 168
Sam Xu Avatar answered Nov 19 '25 12:11

Sam Xu