I have a linq object that I'd like to "retire" when certain aspects are changed and the Save()
method is called. The database does this by having a Terminated column which when set causes the object to be ignored on subsequent queries. I'd like to do this transparently so for example:
DataContext db = new DataContext();
Foo bar = (from a in db.table
where a.pk == somevalue
select a).Single();
bar.Price += 2;
Console.WriteLine(bar.pk);
bar.Save();
Console.WriteLine(bar.pk);
The second WriteLine()
should be a different key than the first because in the process of saving I've created a duplicate object and replaced bar with it. Essentially inside the save method I want to set this = newObj;
. Is what I want possible or am I going about this the wrong way?