2010-04-09 4 views
6

존재하는 엔티티를 첨부 할 수 없습니다,하지만 난이 오류가 점점 오전 :이미 내가 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(); 

답변

15

하는 당신은 필요가 없습니다 엔티티를 첨부하기 위해 이미 컨텍스트에 속합니다.

var con = (from c in cmsContentTable where c.ContentName == contentId select c).FirstOrDefault(); 
con.ContentData = "New Value"; 
cmsContentTable.Context.SubmitChanges(); 
관련 문제