使用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)
因為您不檢索此信息。