Sauce has has the ability to create tables when needed since version 1. No starting with version 1.4.2 you can specify code to execute then a table is created. A great use of this is prepopulate a table with data, like a lookup table for example.

All you have to do is
  1. Define your class as normal
  2. Define a function that will execute the required code (private, public, whatever)
    1. Mark the function with OnTableCreate
    2. The function can, optionally, accept one argument of type IDataStore
  3. use sauce as normal

public class OperationType
{
	public int id { get; set; }
	public string Name { get; set; }

	[OnTableCreate]
	private static void AddDefaultValues(IDataStore dStore)
	{ // this will execute when the table is created
	  dStore.InsertObject(new OperationType() { Name = ">" });
	  dStore.InsertObject(new OperationType() { Name = ">=" });
	  dStore.InsertObject(new OperationType() { Name = "<" });
	  dStore.InsertObject(new OperationType() { Name = "<=" });
	  dStore.InsertObject(new OperationType() { Name = "==" });
	  dStore.InsertObject(new OperationType() { Name = "!=" });
	}
}

Last edited May 30, 2013 at 3:23 AM by iamkrillin, version 2

Comments

No comments yet.