Webapi: Replacement of EnableEnumPrefixFree ?

Created on 1 Feb 2017  路  6Comments  路  Source: OData/WebApi

In Microsoft.AspNet.OData 6.0.0 config.EnableEnumPrefixFree(enumPrefixFree: true); seems to have dissapeared. Is there a replacement for this or another way to accomplish this ? The documentation still references EnableEnumPrefixFree.

Most helpful comment

This worked for me although i did use the ODataModelConventionBuilder so i eventually used the following code :
```
ODataModelBuilder builder = new ODataConventionModelBuilder(config);
var routingConventions = ODataRoutingConventions
.CreateDefaultWithAttributeRouting("odata", config)
.AsEnumerable();

  var route = config.MapODataServiceRoute(
            routeName: "odata",
            routePrefix: "odata",
            configureAction: containerBuilder => containerBuilder
                .AddService(ServiceLifetime.Singleton, sp => builder.GetEdmModel())
                .AddService(ServiceLifetime.Singleton, sp => routingConventions)
                .AddService(ServiceLifetime.Singleton, typeof(ODataUriResolver), 
                        sp => new StringAsEnumResolver { EnableCaseInsensitive = true })
        );

```

Sorry for the late reaction and thanks!

All 6 comments

The same goes for EnableAlternateKeys. Gone in OData 6 although the
documentation still shows it

I was able to replace EnableEnumPrefixFree by registering a StringAsEnumResolver in the configureAction of my call to MapODataServiceRoute.

Action<IContainerBuilder> configureAction = (builder => builder .AddService(ServiceLifetime.Transient, typeof(ODataUriResolver), sp => new StringAsEnumResolver() { EnableCaseInsensitive = true }) );

config.MapODataServiceRoute(routeName, routePrefix, configureAction);

This worked for me although i did use the ODataModelConventionBuilder so i eventually used the following code :
```
ODataModelBuilder builder = new ODataConventionModelBuilder(config);
var routingConventions = ODataRoutingConventions
.CreateDefaultWithAttributeRouting("odata", config)
.AsEnumerable();

  var route = config.MapODataServiceRoute(
            routeName: "odata",
            routePrefix: "odata",
            configureAction: containerBuilder => containerBuilder
                .AddService(ServiceLifetime.Singleton, sp => builder.GetEdmModel())
                .AddService(ServiceLifetime.Singleton, sp => routingConventions)
                .AddService(ServiceLifetime.Singleton, typeof(ODataUriResolver), 
                        sp => new StringAsEnumResolver { EnableCaseInsensitive = true })
        );

```

Sorry for the late reaction and thanks!

Hi @WouterVanmulken, @dmcallis,

I do not have the extension method MapODataServiceRoute either. It seems they have removed in in a recent version. How can I still add the configure action now?

UPDATE: Never mind, I got the wrong class (builder instead of config). sry

Regards

I was searching for this and decided to give it a shot without configuring anything.

It apears that the latest version has this behavior built-in? I was able to call my function without having to specify the enum namespace and it worked correctly.

Hey @julealgon, It might very well be fixed in the new version. This issue was from quite a long time ago when the enum implementation still gave some issues. Unfortunately i haven't been working with OData for quite some time so i can't really comment on it.

Could you confirm that it works in the version your using (and add the version) for all future people reading this thread?

Was this page helpful?
0 / 5 - 0 ratings