Where the CREATE DATABASE statement is generated in Entity Framework Code First with Migrations?

只愿长相守 提交于 2019-12-13 07:20:21

问题


I need to configure the database created by Entity Framework Code First MigrateDatabaseToLatestVersion class.

Is it possible to influence the database files parameters like size or maxsize? What interests me in particular, is there a way to add database files?

I assume I need to find the moment where the Entity Framework generates the CREATE DATABASE statement and influence it a bit. As far as I understand, the SqlServerMigrationSqlGenerator class is too late because the database already exists at this point.


回答1:


Edit: According to comment this doesn't work: You can just add code based migration using Add-Migration command and modify its Up method to execute Sql("ALTER DATABASE ...") and do what ever you want with your database.

Database is created through DbProviderServices - that is a bridging component between EF and specific database server. ObjectContext exposes operations for creating database and generating database creation script. DbMigrator use database creation operation when you execute Update. It checks that if Database exists and if not it uses ObjectContext.CreateDatabase. So if you want to change the process of creating the database you need to implement your own implementation of the migrator to change the way how Update method generates the database (maybe you just need a decorator which will create a database prior to executing DbMigrator.Update operation).



来源:https://stackoverflow.com/questions/11328038/where-the-create-database-statement-is-generated-in-entity-framework-code-first

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