1

Closed

Make all id parameter in EntitySetController by using ODataModelBinder

description

Replace ODataModelBinderProvider globally can cause more problems as it will try to bind all parameters which is not in odata format.
More proper fix is to add modelbinder using ModelBinderAttribute on all id parameters. However, we didn’t make binder type public. So a workaround is to create a custom model binder attribute:
public class ODataModelBinderAttribute : ModelBinderAttribute
{
    public override System.Web.Http.Controllers.HttpParameterBinding GetBinding(System.Web.Http.Controllers.HttpParameterDescriptor parameter)
    {
        ODataModelBinderProvider provider = new ODataModelBinderProvider();
        return new ModelBinderParameterBinding(
            parameter, 
            provider.GetBinder(parameter.Configuration, parameter.ParameterType),
            this.GetValueProviderFactories(parameter.Configuration));
    }
}
Add this attribute to all ID parameter on all actions in EntitySetController.

Without it, user can't support string, guid, long as primary key in odata service.
Closed Jan 3, 2013 at 12:35 AM by hongyes
Verified