Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code First Migration Seed Error: The binary operator Equal is not defined for the types 'System.Nullable`1[System.Int32]' and 'System.Int32'

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.

like image 410
Brian Bruce Avatar asked Jan 30 '15 23:01

Brian Bruce


1 Answers

There is an error in Entity Framework AddOrUpdate method. I created an issue in EF repository:

https://github.com/aspnet/EntityFramework6/issues/9

like image 80
Radosław Maziarka Avatar answered Sep 19 '22 02:09

Radosław Maziarka