I came across this while working on a OData scenario. OData has a binding attribute called ODataParameterBindingAttribute, which has Inherited=true.<br /><br />Scenario: User wants to provide strongly typed properties for the input odata action parameters.<br /><br />Workaround: decorated the binding attribute on the derived types too.<br /><br />Action definition<br />-----------------<br />ActionConfiguration extendSupportDateProduct = modelBuilder.Entity<Product>().Action("ExtendSupportDate");<br />extendSupportDateProduct.Parameter<DateTime>("newDate");<br />extendSupportDateProduct.Returns<bool>();<br /><br /><br />Request<br />-------<br />POST /Products(1)/ExtendSupportDate HTTP/1.1<br />User-Agent: Fiddler<br />Host: localhost:50231<br />Content-Type: application/json;odata=verbose<br />Content-Length: 33<br /><br />{"newDate":"2001-10-25T00:00:00"}<br /><br /><br />Custom Odata Action params<br />--------------------------<br />public class ExtendSupportDateParams : ODataActionParameters<br /> {<br /> public DateTime? NewDate<br /> {<br /> get<br /> {<br /> if (this.ContainsKey("newDate"))<br /> {<br /> return Convert.ToDateTime(this["newDate"]);<br /> }<br /><br /> return null;<br /> }<br /> }<br /> }<br /><br />Does not work (ModelState is invalid and parameters is null)<br />--------------------------------------<br />public bool ExtendSupportDate(int boundId, ExtendSupportDateParams parameters)<br /> {<br /> if (!ModelState.IsValid)<br /> {<br /> throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, this.ModelState));<br /> }<br /><br /> return true;<br /> }<br /><br /><br />Works (ModelState is valid and parameters has request supplied 'newDate' value)<br />---------------------------------------<br />public bool ExtendSupportDate(int boundId, ODataActionParameters parameters)<br /> {<br /> if (!ModelState.IsValid)<br /> {<br /> throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, this.ModelState));<br /> }<br /><br /> return true;<br /> }<br /><br />Expected: <br />Model state should be valid and parameters should be populated in case of the derived type of ODataActionParameters type "ExtendSupportDateParams" as ODataParameterBindingAttribute has inherited attribute on it.<br />Actual:<br />Model state is invalid and parameters is null<br />
↧