LINQ to SQL - Save an entity without creating a new DataContext?

Posted by aximili on Stack Overflow See other posts from Stack Overflow or by aximili
Published on 2010-04-20T02:52:18Z Indexed on 2010/04/20 2:53 UTC
Read the original article Hit count: 567

Filed under:
|
|
|

I get this error

Cannot add an entity with a key that is already in use

when I try to save an Item

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(Item item)
{
  Global.DataContext.Items.Attach(item);
  Global.DataContext.SubmitChanges();

  return View(item);
}

That's because I cannot attach the item to the static global DataContext.

Is it possible to save an item without creating a new DataContext?

(I am very new to LINQ)

© Stack Overflow or respective owner

Related posts about LINQ

Related posts about linq-to-sql