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

Last Reply 8 days ago By jon

Posted 11 days ago

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?

You are viewing reply posted by: jon 8 days ago.
Posted 8 days ago

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);