Knight Data Access Layer
Using IsDirty
Basic Tasks C# > Saving Data > Using IsDirty

Defining an IsDirty property will the application to only save objects that have changes.  This can increase performance when there are a large number of objects to save.  If there is an IsDirty property and it is true OR if there is no IsDirty property, then the object will be updated.

  

//Get the current instance of the helper

IDataHelper db = DataHelper.SessionFactory();

 

Order order = new Order

{

Notes = "Initial notes"

};

 

// New record is inserted

db.Save(order);

Order testOrder = db.LoadByPrimaryKey<Order>(order.OrderId);

 

// Change a property

order.Notes = "Updated notes";

order.IsDirty = false;

 

// Save operation is ignored because IsDirty is false

db.Save(order);

 

// Make it dirty

order.IsDirty = true;

 

// Save updated record

db.Save(order);

 

testOrderDetail = db.LoadByPrimaryKey<Order>(order.OrderId);