title: Error: Cannot apply PATCH to navigation property. So what do I do?
body: <p>I have a Web API 2.2 OData 4 service the following model using entity framework:</p>
  
  <pre><code>public class Company
  {
    public int Id { get; set; }
    public string Name { get; set; }
    public virtual ICollection&lt;CompanyType&gt; CompanyTypes { get; set; }
  }
  
  public class CompanyType
  {
    public int Id { get; set; }
    public string Name { get; set; }
    public virtual ICollection&lt;Company&gt; Companies { get; set; }
  }
  </code></pre>
  
  <p>And a bit of fluent mapping:</p>
  
  <pre><code>modelBuilder.Entity&lt;Company&gt;().HasMany(x =&gt; x.CompanyTypes).WithMany(x =&gt; x.Companies).Map(x =&gt;
  {
    x.MapLeftKey("CompanyId");
    x.MapRightKey("CompanyTypeId");
    x.ToTable("CompaniesCompanyTypes");
  });
  </code></pre>
  
  <p>On my CompanysController I have a patch method and was hoping to be able to send the following request and successfuly update the company name and create a couple of company types records for that company:</p>
  
  <pre><code>PATCH http://localhost:50113/MessagingService/odata//CompanyDTOs(1)/ HTTP/1.1
  Accept: application/json
  Content-Type: application/json; charset=utf-16
  Host: localhost:50113
  Content-Length: 174
  
  {"Name":"Cheesy Peas Ltd","CompanyTypes":[{"Id":1,"Name":"Parent"},{"Id":2,"Name":"Subsidiary"}]}
  </code></pre>
  
  <p>But I receive a:</p>
  
  <pre><code>{
    "error":{
      "code":"","message":"The request is invalid.","innererror":{
        "message":"delta : Cannot apply PATCH to navigation property 'CompanyTypes' on entity type 'Core.Models.Company'.\r\n","type":"","stacktrace":""
      }
    }
  }
  </code></pre>
  
  <p>I assume that I'm asking too much of my PATCH request, but does anyone have a suggestion for how I should achieve this? The simpler the better - I'm not keen on adding complexity to my client application if I can avoid it and would prefer to use PATCH rather that PUT.</p>
  
  <p>Thanks very much. If you're interested in this question and need more details, please ask.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Specifically, what I'm after is to be able to insert a record in a many-to-many table when updating a record in a part of that relationship. Eg. If a Student has many Classes and a Class has many Students then when I update Student A I might also want to add a reference to Class One, delete a reference to Class Two and leave a reference to Class Three intact.</p>
  
  <p>I've done some reading of the OData documentation here:</p>
  
  <p><a href="http://docs.oasis-open.org/odata/odata-atom-format/v4.0/cs02/odata-atom-format-v4.0-cs02.html#_Toc372792732" rel="noreferrer">http://docs.oasis-open.org/odata/odata-atom-format/v4.0/cs02/odata-atom-format-v4.0-cs02.html#_Toc372792732</a></p>
  
  <p>But it's a bit of a mystery to me. I'm sure there must be a way of doing this using things like "@odata.bind" etc.</p>
  
  <p>Any opinions out there?</p>