0
votes

In context of the WCFService with the OData v2 support, I was able to perform a single MERGE request which will change property values of the entity and the references owned by it (through the __metadata object of the request payload).

I've read about $ref requests in OData v4 and CreateRef technique, but it will cost two requests. One to change property values of the entity and the other one to change entity references.

Is there a way to patch an entity and edit its references in one single request in WebAPI with the OData v4 support?

1

1 Answers

0
votes

If you have a 1:n relation you can easily set the foreign key in the request. However your Model must provide a link to the foreign key. Here is an example model (code first):

public class Project
{
    public int ProjectId { get; set; }
    public string Name { get; set; }
    public int ManagerId { get; set; }
    [ForeignKey("ManagerId")]
    public Person Manager { get; set; }
}

In an m:n relation this is not possible because of it's design (EF automatically create a relation table.). However, you can use a custom action an implement the relationship building on your own.