问题
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