Set DatabaseInitializerForType in config file for Custom Initializer to fire

app-config c# ef-code-first entity-framework-6 initialization

Accepted Answer

When using Entity Framework, values from theappSettings portion of the configuration file for your application. Instead, you should utilize the entityFramework.contexts.context.databaseInitializer portion, which looks like this:

    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
        <parameter value="Data Source=.; Integrated Security=True; MultipleActiveResultSets=True" />
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
        <context type="EasyEntity.EasyContext, EasyEntity">
            <databaseInitializer type="EasyEntity.EasyInitializer, EasyEntity" />
9/10/2015 4:27:10 PM

Popular Answer

You can configured the Initializer in the appSettings to respond to the original query. To set the Initializer, utilize reflection as follows:

<add key="DatabaseInitializerForType EasyEntity.EasyContext, EasyEntity" value="System.Data.Entity.DropCreateDatabaseAlways`1[[EasyEntity.EasyContext, EasyEntity]], EntityFramework" />

Disabled may have given you the wrong impression because the result is very different from setting it to "enabled" or "true." You might use the following to access the initializer class if you wanted to execute a "seed" method.

<add key="DatabaseInitializerForType EasyEntity.EasyContext, EasyEntity"  value="EasyEntity.EasyInitializer, EasyEntity" />

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow