0

I am following this tutorial(What's the currently recommended way of performing partial updates with Web API?) to implement partial updates in my web api. But doing so i am getting an error:

  Cannot convert lambda expression to type 'object[]' because it is not a delegate type 

This is my code for partial updates/patch :

   [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);

    }
Community
  • 1
  • 1
Obvious
  • 344
  • 1
  • 3
  • 16
  • 1
    `u.iduser = id` should that be `u.iduser == id`. Single `=` is assignment. – Kami Oct 02 '13 at 09:43
  • Even if i use == , i get the same error – Obvious Oct 02 '13 at 09:48
  • Can you show us what `db.users` contain? And, by the way, why does your method signature say you return a `user` while the code seems to return nothing? Are you still getting the error on the same line of code? – Halvard Oct 02 '13 at 10:04

2 Answers2

2

you could try

var serverUser =db.users.FirstOrDefault(u => u.iduser == id);
if(serverUser != null)
{
    user.Patch(serverUser);
}

Edit Whoops needed ==

Adween
  • 2,792
  • 2
  • 18
  • 20
  • I am getting this error while using your code : Cannot convert lambda expression to delegate type 'System.Func' because some of the return types in the block are not implicitly convertible to the delegate return type – Obvious Oct 02 '13 at 09:45
  • And Cannot implicitly convert type 'int' to 'bool' – Obvious Oct 02 '13 at 09:46
  • @Hmmmmmmmmmm Could you try Adween's suggestion again (after he changed to ==)? – Halvard Oct 02 '13 at 10:05
  • Error has changed now, now i am getting : not all code paths return a value – Obvious Oct 02 '13 at 10:07
  • Yep @Halvard, i tried, now error is changed :not all code paths return a value – Obvious Oct 02 '13 at 10:08
  • @Hmmmmmmmmmm This is because you return nothing but your method signature says you need to return `user`. – Halvard Oct 02 '13 at 10:10
0

Try this:

var serverUser = db.users.Find(u => u.iduser == id);  // == instead of =
Halvard
  • 3,891
  • 6
  • 39
  • 51