How can I generate DDL scripts from Entity Framework 4.3 Code-First Model?

I have a project that I am trying to deploy, and I am using a cheap host to get started. As part of the hosting package, I have a SQL Server database, but I have no exceptions or privileges, I can only use the database that they created for me. In this case, I want to get DDL to start it manually.

I know that I could script to create database scripts from SQL Management Studio, and this might end up working fine, but I would like to automate the process as much as possible, so if I could get the scripts that the Entity Framework creates, which would be perfect.

+4
source share
2 answers

You can generate a script with

Update-Database -Script 

(from the package manager console)

You can find more detailed information in this walkthrough , which also describes some additional options that you may need.

+3
source

You can use Entity Framework Power Tools .

I also wrote a tiny open source tool for this EFScripter .

Two parameters are required: a connection string (it can be as simple as "Integrated Security=SSPI" if you have a local instance of SQL Server) and a DLL containing DbContext.

It writes a script to standard output.

+7
source

Source: https://habr.com/ru/post/1410914/


All Articles