4

I have a project I'm trying to deploy and I'm using a cheap host to get started. As part of the hosting package I have a SQL Server database, but I don't have drop or create privileges, I can only use the database they've created for me. Being that's the case, I want to get the DDL so I can run it manually.

I'm aware I could script the database create scripts from SQL Management Studio, and that may ultimately work fine, but I'd like to automate the process as much as possible, so if I could get the scripts that Entity Framework creates, that would be ideal.

2 Answers 2

7

You can use the Entity Framework Power Tools.

I also wrote a tiny open source tool for that, EFScripter.

It takes two parameters: connection string (it can be as simple as "Integrated Security=SSPI" if you have a local instance of SQL Server), and the dll containing the DbContext.

It writes the script to the standard output.

Sign up to request clarification or add additional context in comments.

Comments

3

You can generate the script using

Update-Database -Script

(from the Package Manager Console)

You can find further details in this walkthrough, which also describes some of the additional options you might need.

7 Comments

Is this a command line tool? If you can elaborate enough that I can find how to execute this command, I will mark as answer.
It's a PS script... you can run it from the package management console.
Updated - as Diego says, this is run from the Nuget Console window.
@Richard this only seems to run if you have migrations (error:No migrations configuration type was found in the assembly)? Can you use it to get a raw dump of the whole DDL?
No, you need to enable migrations (Update-Database is the command to apply migrations).
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.