entity-framework-core - ef core plus:ArgumentNullException:值不能为空。参数名称:属性
问题描述
使用 ef core plus,我正在尝试更新模型上的一组行:
await _context.Set<Critique>()
.Include(c => c.User)
.Where(c => c.Closed && c.User.Id == user.Id)
.UpdateAsync(c => new Critique() { User = deletedUser });
在这里,我得到以下异常:
ArgumentNullException:值不能为空。参数名称:Check.cs 第 21 行中的属性 Npgsql.EntityFrameworkCore.PostgreSQL.Utilities.Check.NotNull(T value, string parameterName)
TargetInvocationException:调用的目标已引发异常。System.RuntimeMethodHandle.InvokeMethod(object target, object[] arguments, Signature sig, bool constructor, bool wrapException
当我只用 ef core 加载数据时,它会加载我期望的 1 行
var test = await _context.Set<Critique>()
.Where(c => c.Closed && c.User.Id == user.Id)
.ToArrayAsync();
数据库模型没什么花哨的,但是太大了,无法在此处发布。我正在广泛使用 [Required],并且有很多一对多关系。
(顺便说一句,user.Id 不为 null 且可用,并且 deletedUser 在代码和数据库中也可用。)
应该如何解释这个错误?我究竟做错了什么?
谢谢你的帮助!
解决方案
我们的库现在可以更新值但不能使用导航属性更新值
这不起作用
.UpdateAsync(c => new Critique() { User = deletedUser });
但是,如果您拥有该财产,这将起作用
.UpdateAsync(c => new Critique() { UserID = deletedUserID });
.Include(c => c.User)
此外,由于您不检索此信息,因此没有必要添加。
推荐阅读
- javascript - 在 ext.net 中重新加载存储时,网格中的记录焦点丢失
- excel - 从特定文件夹子文件夹重命名特定工作表
- tensorflow - 如何将 TensorFlow SavedModel 图转换为 Caffe 模型?
- angular - angular 2 及以上的字体选择器,用于没有互联网连接的系统
- php - 使用jquery php获取下拉列表的选定值
- scala - 用 DataFrame 中的重复项填充空单元格
- amazon-ec2 - terraform destroy 不会删除使用变量的输入参数创建的 ec2 实例
- tumblr - 由于非 http url,Tumblr 不接受我的主题
- python-3.x - 在 Keras 中重新训练使用 train_on_batch() 训练的已保存模型
- google-cloud-platform - 找出如何在 Google Cloud Storage Bucket 中删除文件