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

戏子无情 提交于 2019-12-12 11:19:50

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/10466041/how-can-i-generate-ddl-scripts-from-entity-framework-4-3-code-first-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!