Result creates SQL with Entity Framework 4.1 Code-First

Database.SetInitializer()works fine for testing, but I need SQL output in a file to work in a production environment (database administrators are not going to run a program to create a database). ActiveRecord lock makes file output easy with ActiveRecordStarter.GenerateCreationScripts(). If there is a similar method in EF, I cannot find mention of this. Is this doable?

+3
source share
3 answers

Well, you can run the Database.SetInitializer () method to create the source database for you, and then, as soon as you are satisfied with the database schema, then you can use something like SQL Server Management Studio to generate a script from the database

+3
source

DbContext Sql DDL.

string sqlscript = (context as IObjectContextAdapter).ObjectContext.CreateDatabaseScript();
+9

I think the Entity Designer Database Creation Unit is what you are looking for.

0
source

All Articles