实体框架类库错误

时间:2014-07-11 20:07:27

标签: entity-framework

我在使用Entity Framework 6.1.1尝试update-database时遇到错误:

System.TypeInitializationException: The type initializer for 'System.Data.Entity.Migrations.DbMigrationsConfiguration`1' threw an exception. 
---> System.TypeInitializationException: The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception. 
---> System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize 
---> System.Configuration.ConfigurationErrorsException: Unrecognized configuration section entityFramework. 

在我的App.Config中我有:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <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>
  <connectionStrings>
    <add name="ComicsDatabase" connectionString="Data Source=MoBaT-PC;Initial Catalog=Comics-Database;Integrated Security=True;" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>

2 个答案:

答案 0 :(得分:0)

我必须实际指定所有路径,而不是仅仅执行update-database

  

update-database -ProjectName Comics.DAL -StartUpProjectName Comics.DAL

答案 1 :(得分:0)

为update-database指定 -connectionString -connectionprovidername 参数