我正在按照本教程(What's the currently recommended way of performing partial updates with Web API?)在我的web api中实现部分更新。但这样做我得到一个错误:
Cannot convert lambda expression to type 'object[]' because it is not a delegate type
这是我的部分更新/补丁代码:
[AcceptVerbs("PATCH")]
public user PatchDocument(int id, Delta <user> user)
{
var serverUser =db.users.Find(u => u.iduser = id); // This is where i get error Find(u => u.iduser = id)
user.Patch(serverUser);
}
答案 0 :(得分:2)
你可以尝试
var serverUser =db.users.FirstOrDefault(u => u.iduser == id);
if(serverUser != null)
{
user.Patch(serverUser);
}
编辑需要的哎呀==
答案 1 :(得分:0)
试试这个:
var serverUser = db.users.Find(u => u.iduser == id); // == instead of =