Webapi: Please fix this binding madness

Created on 20 Jul 2016  路  5Comments  路  Source: OData/WebApi

I've had a lot of issues with binding in odata actions and functions for example ...

I have now come to the conclusion that its best to just declare actions as part of of the model and then parse the parameters from the body myself (using something like Newtonsoft.Json) ...

For example I have an Action that I would like to define ...

       Builder.EntityType<Invoice>().Collection.Action("ProcessFile").Parameter<FileEventArgs>("file");

        [HttpPost]
        [ODataRoute("Invoice/ProcessFile()")]
        public async Task<IHttpActionResult> ProcessFile(FileEventArgs file) { 
             return Ok(await service.ProcessFile(file)); 
        }

Yet again, I can't just pass the object in the body of my request I now have to wrap this thing in some container, and yet again I find myself adding containers around my objects purely to have the actual object I want to send as a property of something else for the convenience of some code in the OData framework.

This stuff is really frustrating and I just want to pass my object to the server not some other object that contains my object (an object which actually doesn't exist and thus causes me to have to do non standard things in my client code).
This behaviour is out of the box for the WebAPI framework that the OData code sits on top of, why is this too hard to just take and use as is?

Is this too much to ask?

P3

Most helpful comment

Hi VikingsFan,

The thing I con't seem to understand is why OData can't construct the model internally.
Given a few simple attribs on the controller / actions I think that the OData framework itself could build the model using convention.

With that in mind, I would then in an ideal world just declare my actions just like I would in WebAPI without OData, but in reality this can't happen in many cases because the methods require OData specific things.

I took the time to add a lot more feeback on issue https://github.com/OData/WebApi/issues/758

All 5 comments

@TehWardy sorry for the late reply, as you can see, we are currently working a breaking change release, which involve all the resources, your scenario is very straight forward, ODataActionParameters make thing complicate when there is only one action parameter, your contribution is very welcome while we are running out of resource, or we will try to give a fix or workaround to let you review after our breaking change release.

Hi VikingsFan,

The thing I con't seem to understand is why OData can't construct the model internally.
Given a few simple attribs on the controller / actions I think that the OData framework itself could build the model using convention.

With that in mind, I would then in an ideal world just declare my actions just like I would in WebAPI without OData, but in reality this can't happen in many cases because the methods require OData specific things.

I took the time to add a lot more feeback on issue https://github.com/OData/WebApi/issues/758

See related issue #758. A lot of discussion around these issues.

https://github.com/OData/WebApi/issues/1922 is probably related to this in some way.

3 years later nothing has changed here, even pulling the latest .Net core based build hasn't changed the situation.
I figure that the reasoning here is something to do with the way the OData standard is defined / works and given that there's way more important stuff i would like to see resolved (as i'm sure many others would too).

As long as we are aware of OData's "peculiarities" we as consumers can work around this making it extremely low priority at best.

At this point I figure this can be dropped at this point as a "will not fix, working as intended" (despite the weirdness).

Was this page helpful?
0 / 5 - 0 ratings