Entity Framework Error: Unable to track an entity of type OrderItem because primary key property ProductVariant is null

jon
 
on Apr 11, 2019 07:10 AM
6619 Views

hi

in my OrderItems table i need a composite key as

Id, ProductCode,ProductVariant

I tested insert in sqlite with null ProductVariant but from webapi post

i recive error

InvalidOperationException: Unable to track an entity of type 'OrderItem' because primary key property 'ProductVariant' is null.

Microsoft.EntityFrameworkCore.ChangeTracking.Internal.NullableKeyIdentityMap<TKey>.Add(InternalEntityEntry entry)

 

How can solve?

Download FREE API for Word, Excel and PDF in ASP.Net: Download
jon
 
on Apr 14, 2019 04:05 AM

Now i solved with a raw query and inside

if (item.Codvar == null)
    Codvar = new SqliteParameter("@Codvar", DBNull.Value);
else
    Codvar = new SqliteParameter("@Codvar", item.Codvar);