Change tracking for updates

schotime edited this page Apr 29, 2013 · 4 revisions

Using the Snapshotter

The snapshot is used to track the changes to the entity, so that only the properties that have changed will be updated. In the following example only the new Name will be sent to the database, as the Age value is the same as it was when the snapshot was started.

IDatabase db = new Database("connString");
var user = db.SingleById<User>(1);  // Name = "Ted", Age = 21

var snapshot = db.StartSnapshot(user);  // Any changes after this will be recorded.

user.Name = "Bobby";
user.Age = 21;

db.Update(user, snapshot.UpdatedColumns());  // Only the Name column will be updated

Only the changes that have been made before UpdatedColumns() is called will be included in the change-set.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.