I want to run a function whenever a change is made in the database.
Is there a way to avoid 3 loops to do so ? Here is my code:
public void Save()
{
System.Data.Linq.ChangeSet changeSet = db.GetChangeSet();
foreach (User user in changeSet.Inserts)
{
this.doSomeStuff();
}
foreach (User user in changeSet.Updates)
{
this.doSomeStuff();
}
foreach (User user in changeSet.Deletes)
{
this.doSomeStuff();
}
db.SubmitChanges();
}
Just “converting” @adrianm comment into an answer: