Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I patch/update foreign key with OData.Delta?

Trying to make use of System.Web.Http.OData.Delta to implement PATCH methods in ASP.NET Web API services, but it seems unable to apply changes to foreign key relation properties.

consider this data type, which it should be possible to update in a PATCH request to the Web API service:

public class Company
{
    public int ID { get; set; }
    // [Required]
    public String Name { get; set; }
    public string Description { get; set; }
    public int ? CountryID { get; set; }
    [ForeignKey("CountryID")]
    public virtual Country Country { get; set; }

}

Every thing works fine when I update name/ description properties.However, when i try to update the country Id property,I can see following request originating from browser.

CountryID: 3
Description: "e"
ID: 10
Name: "EF" 

But at server side both country object and country id property is always null in Delta<Company> object.

Any idea how to upate foreign keys using delta/patch?

like image 945
Nabeel Avatar asked Oct 17 '25 13:10

Nabeel


1 Answers

Just found that OData Delta<t> only update properties that are basic types or classes. Inherited classes, nullables, generics, integer,derived types aren't supported yet. (May be supported in future releases).

I have solved this problem using deserialization method from a sample available here:

Link

like image 127
Nabeel Avatar answered Oct 20 '25 04:10

Nabeel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!