You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using OData Attribute Routing and the Attribute Routing Convention a single host cannot handle multiple EDM models.
I am not sure the best solution to resolve this, here is the work around we came up with to solve this.
[AttributeUsage(AttributeTargets.Class, AllowMultiple =false, Inherited =false)]publicsealedclassODataModelAttribute:Attribute{publicODataModelAttribute(stringcontainerFullName){ContainerFullName=containerFullName;}publicstringContainerFullName{get;privateset;}}publicclassModelBoundODataAttributeRoutingConvention:AttributeRoutingConvention{publicoverrideboolShouldMapController(HttpControllerDescriptorcontroller){if(controller==null){returnbase.ShouldMapController(null);}varodataModelAttribute= controller.GetCustomAttributes<ODataModelAttribute>().FirstOrDefault();if(odataModelAttribute==null){returnbase.ShouldMapController(controller);}// This should be case sensitive since OData is case sensitivereturn odataModelAttribute.ContainerFullName.Equals(
Model.EntityContainer.FullName(),
StringComparison.Ordinal);}}publicstaticclassHttpConfigurationExtensions{publicstatic ODataRoute MapModelBoundODataServiceRoute(thisHttpConfigurationconfiguration,stringrouteName,stringroutePrefix,IEdmModelmodel){varconventions=(new[]{new ModelBoundODataAttributeRoutingConvention(model, configuration)}).Concat(
ODataRoutingConventions.CreateDefault());return System.Web.OData.Extensions.HttpConfigurationExtensions.MapODataServiceRoute(
configuration,
routeName,
routePrefix,
model,new DefaultODataPathHandler(),
conventions);}}
When using OData Attribute Routing and the Attribute Routing Convention a single host cannot handle multiple EDM models.
I am not sure the best solution to resolve this, here is the work around we came up with to solve this.
And some sample usage.
The text was updated successfully, but these errors were encountered: