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:

  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="Data Source=.; Integrated Security=True; MultipleActiveResultSets=True" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
    <contexts>
        <context type="EasyEntity.EasyContext, EasyEntity">
            <databaseInitializer type="EasyEntity.EasyInitializer, EasyEntity" />
        </context>
    </contexts>
  </entityFramework>
1
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:

<appSettings>
<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.

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


Related Questions





Related

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