Unable to attach entity that already exists

I am trying to update the code through Linq, but I am getting this error:

Unable to bind an entity that already exists.

C # code is here:

var con = (from c in cmsContentTable where c.ContentName == contentId select c).FirstOrDefault(); cmsContentTable.Attach(con); con.ContentData = "New Value"; cmsContentTable.Context.SubmitChanges(); 
+6
c # linq-to-sql
source share
1 answer

You do not need to attach the object, it already belongs to the context.

 var con = (from c in cmsContentTable where c.ContentName == contentId select c).FirstOrDefault(); con.ContentData = "New Value"; cmsContentTable.Context.SubmitChanges(); 
+15
source share

All Articles