gpt4 book ai didi

c# - Code First 迁移种子错误 : The binary operator Equal is not defined for the types 'System.Nullable` 1[System. Int32 ]' and ' System.Int32'

转载 作者:可可西里 更新时间:2023-11-01 09:12:55 43 4
gpt4 key购买 nike

在我的数据库中播种时,我的更新标识符出现以下问题:

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

因为 cp.Recommendation_IDcp.PromoCode_IDint?数据类型,它得到以下错误:

The binary operator Equal is not defined for the types 'System.Nullable`1[System.Int32]' and 'System.Int32'.

我查看了这篇文章并添加了 modelBuilder - IsOptional() 描述的代码,但它对我不起作用,我在 this question 中遇到了同样的错误。

如果我改变:

cp => new { cp.ClientID, cp.Recommendation_ID, cp.PromoCode_ID }

收件人:

cp => new { cp.ClientID }

它工作正常,但是如果我需要更新记录,这将不起作用,它只会复制表中的每条记录。

最佳答案

Entity Framework 的 AddOrUpdate 方法有错误。我在 EF 存储库中创建了一个问题:

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

关于c# - Code First 迁移种子错误 : The binary operator Equal is not defined for the types 'System.Nullable` 1[System. Int32 ]' and ' System.Int32',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28246082/

43 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com