Danish Ali
Danish Ali

Reputation: 294

How to create SQL Server database using Entity Framework database-first code?

How to create a SQL Server database using Entity Framework databbase-first code?

I've mistakenly deleted the database from SQL Server, but I've added EDO in model at my VS 2017 project. So, now I've EDO code, can I restore database with the help of that code ?

Upvotes: 1

Views: 2270

Answers (2)

Samim Hussain
Samim Hussain

Reputation: 416

Exporting an Entity Data Model to a SQL-Server database

  1. Open the SQL Server Management Studio.
  2. Right click on Databases, select New Database
  3. Type MyFirstEF on Database name. Click OK.
  4. We're going to set the connection properties for your database from Visual Studio:
  5. Right-click on the EDM design mode, select Generate Database from Model
  6. Click on New Connection.
  7. Type your SQL-Server host name on Server name field.
  8. Select the database you created in Step 3 on the field Select or enter a database name. Click OK.
  9. Click Next.
  10. Choose a version of Entity Framework that you use . Click Next. You have just generated the script to create the database. For step by step walk-through click here

enter image description here

Upvotes: 0

DhavalR
DhavalR

Reputation: 1417

If you are able to open edmx in Model Browser in Visual Studio, you can generate script for database by right clicking on edmx diagram. Select Generate Database from Model.

FYI : This will generate only basic structure. Not stored procedure, udf's etc.

enter image description here

And you will get script as below.

enter image description here

Upvotes: 1

Related Questions