Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 320
Ali Foroughi Avatar asked Jan 24 '26 10:01

Ali Foroughi


1 Answers

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:

  • Automatic Code First Migrations
  • Code First Migrations

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

like image 83
AlexC Avatar answered Jan 26 '26 00:01

AlexC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!