I created a DBContext Initializer:
Public Class DropCreateInitializer(Of T As DbContext)
Inherits DropCreateDatabaseIfModelChanges(Of T)
Protected Overrides Sub Seed(context As T)
context.Database.ExecuteSqlCommand("CREATE INDEX IX_EXPLAN ON DBO.EXPLANS (PROGNAME, BIND_TIME, ACCESSNAME)")
End Sub
End Class
What I dont understand is how to control the SQL server the new context will create a database on. It gets created on localhost/SQLEXPRESS.
The
DbContextclass optionally takes a connection string as a constructor parameter, which means you can programatically build up a connection string using the System.Data.SqlClient.SqlConnectionStringBuilder class.Here is an example, in C# (I know your sample is in vb.net, but the translation should be simple enough, and this should illustrate the approach):