使用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:值不能为null。参数名称:Check.cs中的属性Npgsql.EntityFrameworkCore.PostgreSQL.Utilities.Check.NotNull(T value,string parameterName),第21行
TargetInvocationException:调用目标抛出了异常。 System.RuntimeMethodHandle.InvokeMethod(object target,object []参数,Signature sig,bool构造函数,bool wrapException
当我用ef核心加载数据时,它会加载我期望的1行
var test = await _context.Set<Critique>()
.Where(c => c.Closed && c.User.Id == user.Id)
.ToArrayAsync();
数据库模型没什么特别的,但是太大了,不能在这里发布。我广泛使用[必需],并且有很多一对多的关系。
(顺便说一句,user.Id不是null并且可用,并且在代码和数据库中也可以使用deletedUser。)
该错误应如何解释?我究竟做错了什么?
谢谢你的帮助!
我们的库可以更新值,但此时无法使用导航属性更新值
这不起作用
.UpdateAsync(c => new Critique() { User = deletedUser });
但如果您拥有该物业,这将有效
.UpdateAsync(c => new Critique() { UserID = deletedUserID });
此外,没有必要添加.Include(c => c.User)
因为您不检索此信息。