Reputation: 57
I have no idea, where should I set up System.Data.Entity.DropCreateDatabaseAlways parameter in my App.config file.
I do understand, that config section named "entityFramework" is defined here. I presume this section should be used. But I can't find any example of this type App.config file.
I'm using EF6.0 and SqlServer Compact.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
<parameters>
<parameter value="System.Data.SqlServerCe.4.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SqlServerCe.4.0" />
<add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
</DbProviderFactories>
</system.data>
</configuration>
Upvotes: 0
Views: 508
Reputation: 8991
You can set the database initializer either within your DbContext
class or in your web.config
file. Both examples follow:
public class YourDBContext : DbContext
{
public YourDBContext() : base("connstr")
{
Database.SetInitializer<YourDBContext>(new DropCreateDatabaseAlways<YourDBContext>());
}
...
}
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="DatabaseInitializerForType Namespace.YourDBContext, Assembly"
value="System.Data.Entity.DropCreateDatabaseAlways`1[[Namespace.YourDBContext, Assembly]], EntityFramework" />
</appSettings>
</configuration>
See Database Initialization Strategies in Code-First.
Upvotes: 1