private static void ConfigureWebApiOData(HttpConfiguration config)
        {
            var controllerSelector = new ODataVersionControllerSelector(config);
            config.Services.Replace(typeof(IHttpControllerSelector), controllerSelector);

            // Define a versioned route
            config.MapODataServiceRoute("V1RouteVersioning", "odata/v1", GetVersionedModel());
            controllerSelector.RouteVersionSuffixMapping.Add("V1RouteVersioning", "V1");

            // Define a versioned route that doesn't map to any controller
            config.MapODataServiceRoute("odata/v2", "odata/v2", GetFakeModel());
            controllerSelector.RouteVersionSuffixMapping.Add("odata/v2", "V2");

            // Define a custom route with custom routing conventions
            var conventions = ODataRoutingConventions.CreateDefault();
            conventions.Insert(0, new CustomNavigationPropertyRoutingConvention());
            var customODataRoute = config.MapODataServiceRoute("CustomODataRoute", ODataRoutePrefix, GetCustomRouteModel(), batchHandler: null, pathHandler: new DefaultODataPathHandler(), routingConventions: conventions);
            config.AddCustomSwaggerRoute(customODataRoute, "/Customers({Id})/Orders")
                .Operation(HttpMethod.Post)
                .PathParameter<int>("Id")
                .BodyParameter<Order>("order");

            // Define a route to a controller class that contains functions
            config.MapODataServiceRoute("FunctionsODataRoute", ODataRoutePrefix, GetFunctionsEdmModel());

            // Define a default non- versioned route(default route should be at the end as a last catch-all)
            config.MapODataServiceRoute("DefaultODataRoute", ODataRoutePrefix, GetDefaultModel());
        }
        private static void ConfigureWebApiOData(HttpConfiguration config)
        {
            var controllerSelector = new ODataVersionControllerSelector(config);
            config.Services.Replace(typeof(IHttpControllerSelector), controllerSelector);

            // Define a versioned route
            config.MapODataServiceRoute("V1RouteVersioning", "odata/v1", GetVersionedModel());
            controllerSelector.RouteVersionSuffixMapping.Add("V1RouteVersioning", "V1");

            // Define a versioned route that doesn't map to any controller
            config.MapODataServiceRoute("odata/v2", "odata/v2", GetFakeModel());
            controllerSelector.RouteVersionSuffixMapping.Add("odata/v2", "V2");

            // Define a custom route with custom routing conventions
            var conventions = ODataRoutingConventions.CreateDefault();
            conventions.Insert(0, new CustomNavigationPropertyRoutingConvention());
            var customODataRoute = config.MapODataServiceRoute("CustomODataRoute", ODataRoutePrefix, GetCustomRouteModel(), batchHandler: null, pathHandler: new DefaultODataPathHandler(), routingConventions: conventions);
            config.AddCustomSwaggerRoute(customODataRoute, "/Customers({Id})/Orders")
                .Operation(HttpMethod.Post)
                .PathParameter<int>("Id")
                .BodyParameter<Order>("order");

            // Define a route to a controller class that contains functions
            config.MapODataServiceRoute("FunctionsODataRoute", ODataRoutePrefix, GetFunctionsEdmModel());

            // Define a default non- versioned route(default route should be at the end as a last catch-all)
            config.MapODataServiceRoute("DefaultODataRoute", ODataRoutePrefix, GetDefaultModel());

            bool isPrefixFreeEnabled = System.Convert.ToBoolean(WebConfigurationManager.AppSettings["EnableEnumPrefixFree"]);
            var uriResolver = isPrefixFreeEnabled ? new StringAsEnumResolver() : new ODataUriResolver();

            // Define a route with an enum as a key
            const string enumRouteName = "EnumODataRoute";
            config.MapODataServiceRoute(enumRouteName,
                                        ODataRoutePrefix,
                                        builder => builder
                                            .AddService(ServiceLifetime.Singleton, sp => GetProductWithEnumKeyModel())
                                            .AddService(ServiceLifetime.Singleton, sp => (IEnumerable<IODataRoutingConvention>)ODataRoutingConventions.CreateDefaultWithAttributeRouting(enumRouteName, config))
                                            .AddService(ServiceLifetime.Singleton, sp => uriResolver));

            // Define a route with an enum/int composite key
            const string enumIntCompositeRouteName = "EnumIntCompositeODataRoute";
            config.MapODataServiceRoute(enumIntCompositeRouteName,
                                        ODataRoutePrefix,
                                        builder => builder
                                            .AddService(ServiceLifetime.Singleton, sp => GetProductWithCompositeEnumIntKeyModel())
                                            .AddService(ServiceLifetime.Singleton, sp => (IEnumerable<IODataRoutingConvention>)ODataRoutingConventions.CreateDefaultWithAttributeRouting(enumIntCompositeRouteName, config))
                                            .AddService(ServiceLifetime.Singleton, sp => uriResolver));
        }