gpt4 book ai didi

c# - 值不能为空。参数名称 : source

转载 作者:IT王子 更新时间:2023-10-29 03:35:13 25 4
gpt4 key购买 nike

这可能是我花了很长时间解决的最浪费时间的问题。

var db = new hublisherEntities();
establishment_brands est = new establishment_brands();

est.brand_id = 1;
est.establishment_id = 1;
est.price = collection["price"];
est.size = collection["size"];

db.establishment_brands.Add(est);
db.SaveChanges();

这给了我一个错误

Value cannot be null. Parameter name: source

堆栈跟踪

[ArgumentNullException: Value cannot be null. Parameter name: source] System.Linq.Enumerable.Any(IEnumerable1 source, Func2 predicate) +4083335 System.Data.Entity.Internal.InternalContext.WrapUpdateException(UpdateException updateException) +87
System.Data.Entity.Internal.InternalContext.SaveChanges() +193
System.Data.Entity.Internal.LazyInternalContext.SaveChanges() +33
System.Data.Entity.DbContext.SaveChanges() +20 ... ...

我只想向表中添加一个实体。 ORM 是 EF。

最佳答案

DbContext 中的某处是一个 IEnumerable 的值,使用 Any()(或 Where() 查询Select() 或任何其他 LINQ 方法),但此值为 null

查明您是否在使用 LINQ 方法的地方将查询放在一起(在您的示例代码之外的某个地方),或者您是否使用了 IEnumerable 作为 NULL 参数。

关于c# - 值不能为空。参数名称 : source,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16281133/

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