OData client unable to send null values for Key properties
<p>I have built an OData WebAPI Service exposing a couple of entities (using OData 4, System.Web.Odata v5.1.9). </p>

<p>The service accepts bost POST (for creating) and PATCH (for updating). Internally, both POST and PATCH are forwarded to an Oracle database, and both methods are handled through a single stored procedure which takes the Id as an input parameter. If the Id is null, a new record is created, otherwise the record with that Id is updated.</p>

<p>Recently one of our consumers complained that they can't properly insert new data. The problem is that they use the OData client to generate their model using the metadata. As the Id is not nullable a 0 is always sent to my service, prompting the database routine to do an update of record with Id 0 (which doesn't exist, raising an exception).</p>

<p>Now, there's a couple options I see to circumvent this:</p>

<ul>
<li>in my controller check if Id is default(int) and if so pass NULL to the SP</li>
<li>stop using the OData client and have them construct their messages manually</li>
<li>separate the single stored procedure into two procedures (insert and update)</li>
<li>change the Id property to a string</li>
</ul>

<p>My Entity class looks like this:</p>

<pre><code>public class ContactDTO
    {
        [Key]
        public int Id { get; set; }

        [ForeignKey("Person")]
        public int? PersonId { get; set; }

        // snip some other properties
    }
</code></pre>

<p>Because the Id property is defined as [Key] it is shown in the metadata as Required:</p>

<pre><code>&lt;EntityType Name="ContactDTO"&gt;
    &lt;Key&gt;
        &lt;PropertyRef Name="Id"/&gt;
    &lt;/Key&gt;
    &lt;Property Name="Id" Type="Edm.Int32" Nullable="false"/&gt;
    &lt;Property Name="PersonId" Type="Edm.Int32"/&gt;
&lt;/EntityType&gt;
</code></pre>

<p>I have a feeling that I'm missing something here and that maybe I should just leave it as is, but if not, what are the steps I can take to make sure they can call my service properly</p>