오전에 첨부 할 수 있습니다처럼 코드는 모습입니다 부분 클래스 영웅 ...System.InvalidOperationException는 : 엔티티 만 여기 <code>DataContext</code>를 사용하고, "히어로"라는 테이블을 업데이트하려고 수정
public partial class Hero : IHero {
//my fields and methods etc...
public void Save() {
using(GameDBDataContext db = new GameDBDataContext()) {
db.Heros.Attach(this, true);
db.SubmitChanges();
}
}
}
하지만이 던지고 : -
System.InvalidOperationException: An entity can only be attached as modified without original state if it declares a version member or does not have an update check policy.
어를 이 문제의 해결책은 무엇입니까?
public void Save() {
using(GameDBDataContext db = new GameDBDataContext()) {
db.Heros.Attach(this, db.Heros.SingleOrDefault(x => x.id == EntityID));
}
}
과 예외 : -이 - :
편집 : 나는 이것을 시도 System.NotSupportedException: An attempt has been made to Attach or Add an entity that is not new, perhaps having been loaded from another DataContext. This is not supported.
나는 이것을 시도해보고 System.NotSupportedException을 throw한다. 새로운 DataContext에서로드 된 엔티티를 Attach하거나 Add하려고 시도했다. 이것은 지원되지 않습니다. ' – Abanoub