开发者

Cannot attach an entity that already exists

开发者 https://www.devze.com 2022-12-26 11:20 出处:网络
I am trying to update code via Lin开发者_Go百科q, but I am getting this error: Cannot attach an entity that already exists.

I am trying to update code via Lin开发者_Go百科q, but I am getting this error:

Cannot attach 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();


You don't need to attach the entity, 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(); 
0

精彩评论

暂无评论...
验证码 换一张
取 消