I have the following issue with my update identifiers when seeding to my db:
context.ClientPromos.AddOrUpdate(
cp => new { cp.ClientID, cp.Recommendation_ID, cp.PromoCode_ID },
new ClientPromo
{
ClientID = 0,
Recommendation_ID = Rec30Off.RecommendationID,
PromoCode_ID = pc30PerOffProd.PromoCodeID
},
new ClientPromo
{
ClientID = 0,
Recommendation_ID = RecKnow.RecommendationID,
},
new ClientPromo
{
ClientID = 0,
Recommendation_ID = RecCall.RecommendationID,
},
);
context.SaveChanges();
Since cp.Recommendation_ID
and cp.PromoCode_ID
are int? datatypes
, it gets the following error:
The binary operator Equal is not defined for the types 'System.Nullable`1[System.Int32]' and 'System.Int32'.
I have viewed this article and added the modelBuilder
- IsOptional()
code described, but it doesn't work for me and I get the same error in this question.
If I change:
cp => new { cp.ClientID, cp.Recommendation_ID, cp.PromoCode_ID }
To:
cp => new { cp.ClientID }
It works fine, however this will not work if I need to update a record it will just duplicate every record in the table.
There is an error in Entity Framework AddOrUpdate method. I created an issue in EF repository:
https://github.com/aspnet/EntityFramework6/issues/9
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With