Ninja Database Pro
Using IsDirty
Basic Tasks > Using IsDirty

When saving a list of items, if the IsDirty property is false, the item will not be saved.  Simply put an IsDirty property on your class to use this functionality.  The IsDirty is automatically set to false after the save is complete.  To disable the IsDirty functionality, put a DisableAuto attribute on the IsDirty property.

 

//Create a couple vendors

List<Vendor> vendors = new List<Vendor>();

 

Vendor vendor1 = new Vendor();

vendor1.Name = "Acme Rocket Motors Inc.";

vendor1.IsDirty = true;

vendors.Add(vendor1);

 

Vendor vendor2 = new Vendor();

vendor2.Name = "Acme Windshield Wipers Inc.";

vendor2.IsDirty = false;

vendors.Add(vendor2);

 

_ninjaDbPro.Save(vendors);

 

//Vendor 1 is saved

Vendor vendor1Copy = _ninjaDbPro.Load<Vendor>(vendor1.VendorID);

 

//Vendor 2 will be null since IsDirty was false

Vendor vendor2Copy = _ninjaDbPro.Load<Vendor>(vendor2.VendorID);