我试图通过
Linq更新代码,但我收到此错误:
Cannot attach an entity that already exists.
C#代码在这里:
var con = (from c in cmsContentTable where c.ContentName == contentId select c).FirstOrDefault(); cmsContentTable.Attach(con); con.ContentData = "New Value"; cmsContentTable.Context.SubmitChanges();
解决方法
您不需要附加实体,它已经属于上下文.
var con = (from c in cmsContentTable where c.ContentName == contentId select c).FirstOrDefault(); con.ContentData = "New Value"; cmsContentTable.Context.SubmitChanges();