private static void TestPrefixConfig(string tableNamePrefix, string testSql) { // arrange var enumToLookup = new EnumToLookup { TableNamePrefix = tableNamePrefix }; TestConfig(testSql, enumToLookup); }
public void ExampleOfUsingApply() { using (var context = new MyDbContext()) { var enumToLookup = new EnumToLookup(); enumToLookup.NameFieldLength = 42; // optional, example of how to override default values // This would normally be run inside either a db initializer Seed() // or the migration Seed() method which both provide access to a context. enumToLookup.Apply(context); } }
private static void TestConfig(string testSql, EnumToLookup enumToLookup) { Database.SetInitializer(new TestInitializer(enumToLookup)); using (var context = new MagicContext()) { var roger = new Rabbit { Name = "Roger", TehEars = Ears.Pointy }; context.PeskyWabbits.Add(roger); context.SaveChanges(); // assert context.Database.ExecuteSqlCommand(testSql); // should explode if anything is wrong } }
public void ExampleOfGeneratingSql() { using (var context = new MyDbContext()) { var enumToLookup = new EnumToLookup(); // if you need to get at the raw sql to run a migration separately then use: var migrationSql = enumToLookup.GenerateMigrationSql(context); // you'd probably want to write this to a file and then add it to source control, but for // the purpose of demonstration we'll write it to the console instead: Console.Out.WriteLine(migrationSql); // at some point you'd then run the sql (probably not like this, but this serves as a test that it's working) context.Database.ExecuteSqlCommand(migrationSql); } }