mld
mld

Reputation: 519

Output create SQL with Entity Framework 4.1 Code-First

Database.SetInitializer() works great for testing, but I need the SQL output in a file for working in a production environment (DBAs aren't going to run a program to create the DB). Castle ActiveRecord make output to a file easy with ActiveRecordStarter.GenerateCreationScripts(). If there's a similar method in EF, I'm unable to find any mention of it. Is this doable?

Upvotes: 3

Views: 2034

Answers (3)

haladaj
haladaj

Reputation: 91

You can also use the DbContext to get the Sql DDL.

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

Upvotes: 9

nathan gonzalez
nathan gonzalez

Reputation: 11987

i think the Entity Designer Database Generation Power Pack is probably what you're looking for.

Upvotes: 0

Tib
Tib

Reputation: 272

Well you could run the Database.SetInitializer() method to create the initial database for you and then once you are satisfied with the database schema then you could possibly use something like SQL Server Management Studio to generate the script from the database

Upvotes: 3

Related Questions