'TypeLoadException:无法为web.config中的Entity Framework databaseInitializer加载类型'

时间:2013-07-03 14:51:35

标签: entity-framework web-config

我正在尝试将Entity Framework DBContext的databaseInitializer设置为DropCreateDatabaseIfModelChanges

在我的web.config中使用以下条目:

<entityFramework>
  <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  <contexts>
    <context type="Domain.EVRMDBContext, EVRM">
      <databaseInitializer type="System.Data.Entity.DropCreateDatabaseIfModelChanges, EntityFramework" />
    </context>
  </contexts>

但我得到例外:

[TypeLoadException: Could not load type 'Domain.EVRMDBContext' from assembly 'EVRM'.]
--snip--
[InvalidOperationException: Failed to set database initializer of type   'System.Data.Entity.DropCreateDatabaseIfModelChanges, EntityFramework' for DbContext type 'Domain.EVRMDBContext, EVRM' specified in the application configuration. See inner exception for details.]

我怀疑对DBContext的引用不正确(Domain.EVRMDBContext, EVRM)。在我的项目的根目录是一个Domain包,它包含EVRMDBContext类。

My solution's contents

1 个答案:

答案 0 :(得分:0)

您还需要指定DropCreateDatabaseIfModelChanges的类型:

<databaseInitializer
     type="System.Data.Entity.DropCreateDatabaseIfModelChanges`1[[Domain.EVRMDBContext, EVRM]], EntityFramework" />