简体   繁体   中英

Generate DDL Script to create database in Entity Framework

I am creating an application using Entity Framework code-first.

How can I create the database using this model? Is it possible to create the DDL scripts from a code-first approach just like the DDL scripts that can be generated from a model first approach?

Update : Generate a sql server script from Entity Framework code-first architecture

Using Entity Framework Code-First the application, when run, will create the database and tables that support your .Net model classes. Therefore using this approach you don't need DDL scripts as the work will be done for you by the application.

In Entity Framework there has been a lot of effort put into the Migrations tool to enable the deployment of db changes. This is detailed here:

This seems to offer the most effective way of deploying db changes to multiple target environments.

Code First is not particularly capable when it comes to local database deltas. If you are doing anything with OnModelCreating within your db context then this will require your database to be deleted then recreated by the code first application. This is required by code first to ensure that the code model and the persistence model are kept synchronised.

These are two good starter tutorials on MVC with an EF component.

Code-First Development with Entity Framework 4

Intro to ASP.NET MVC 3

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM