且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MVC4项目-无法DropCreateDatabaseIfModelChanges

更新时间:2022-12-13 11:59:46

不要理会此机制.对于生产应用程序来说,这是不可行的,并且需要您在模式每次更改时都对所有数据进行缓冲.

Don't bother with this mechanism. It's not feasible for production apps and requires you to hose all your data each time the schema changes.

相反,将数据库架构创建为一个单独的SSDT项目,并使用DACPAC文件来初始部署和升级生产数据库,同时保持所有数据不变.只需将SimpleMembership创建的表复制到您的SSDT项目中即可.

Instead create your database schema as a separate SSDT project and use DACPAC files to initially deploy and upgrade your production database while keeping all the data intact. Just copy the tables that SimpleMembership creates into your SSDT project.

通过这种方式,您可以精确地定义列,可以精确地定义约束,可以精确地定义外键,主键和唯一键等,并且仍然可以通过应用程序项目中的Entity Framework访问数据.升级生产数据库上的架构仅需要部署DACPAC.

This way you have exact column definitions, can exactly define constraints, exactly define foreign keys, primary keys and unique keys etc. and still access your data through Entity Framework in your application project. Upgrading the schema on the production database simply requires a DACPAC to be deployed.

在开发过程中,当您在SSDT中进行更改时,Visual Studio将自动对表结构进行任何更改.

During development, Visual Studio will automatically make any changes to the table structure when you make changes in SSDT.

简而言之,我认为以代码为先的定义太松散,太杂乱无章,是个坏主意.

In short I think code-first is too loosely defined, unorganised and a bad idea.