Skip to content

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.