am trying to update table called "Hero" , am using DataContext
, here is how the codes looks like:-
//linq to sql table (automatic generated)
[global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.Hero")]
public partial class Hero : INotifyPropertyChanging, INotifyPropertyChanged
{
//fields methods etc..
}
and there is my own partial class Hero ...
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();
}
}
}
but it's throwing this :-
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.
what is the solution for this problem?
EDIT: I have tried this :-
public void Save() {
using(GameDBDataContext db = new GameDBDataContext()) {
db.Heros.Attach(this, db.Heros.SingleOrDefault(x => x.id == EntityID));
}
}
and it throws :- 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.