Entity framework 使用EF6 SQL Server CE代码创建数据库首先崩溃

Entity framework 使用EF6 SQL Server CE代码创建数据库首先崩溃,entity-framework,sql-server-ce,code-first,entity-framework-6,dbcontext,Entity Framework,Sql Server Ce,Code First,Entity Framework 6,Dbcontext,我在运行应用程序时看到此错误 [MissingMethodException: Method not found: 'System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher System.Data.Entity.Infrastructure.Interception.DbDispatchers.get_Connection()'.] System.Data.Entity.SqlServerCompact.S

我在运行应用程序时看到此错误

[MissingMethodException: Method not found: 'System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher System.Data.Entity.Infrastructure.Interception.DbDispatchers.get_Connection()'.]
   System.Data.Entity.SqlServerCompact.SqlCeProviderServices.DbCreateDatabase(DbConnection connection, Nullable`1 timeOut, StoreItemCollection storeItemCollection) +0
   System.Data.Entity.Core.Common.DbProviderServices.CreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection) +75
   System.Data.Entity.Core.Objects.ObjectContext.CreateDatabase() +132
代码:

var db = new AuditDb();
db.Database.CreateIfNotExists(); // blows up! 
or
db.Set<CampaignAudit>().Find(0); // same error
背景:

[DbConfigurationType("MvcTest.Data.AuditDBConfiguration, MvcTest")]
public class AuditDb : DbContext
{
    // tried this approach as well:
    // static AuditDb() { Database.SetInitializer(new CreateDatabaseIfNotExists<AuditDb>()); }
    public AuditDb() : base ("Name=AuditDB"){}
    public DbSet<CampaignAudit> Audits { get; set; }

    protected override void OnModelCreating(DbModelBuilder builder)
    {

        Map<CampaignAudit>(builder);
        ...
}
Web.Config:

<add name="AuditDB" providerName="System.Data.SqlServerCe.4.0" connectionString="Data Source=C:\logs\GroundAuditDb.sdf" />

<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>
<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>
因此尝试启用迁移:

Enable-Migrations -ContextTypeName MvcTest.Data.AuditDb
这就是投掷:

Method not found: 'Void System.Data.Entity.ModelConfiguration.Configuration.EntityMappingConfiguration`1.MapInheritedProperties()
这是一连串看不到尽头的错误


有没有人能够让EF6以SQL CE代码优先的方式工作

我的解决方案中也有同样的问题。问题是我在解决方案中的不同项目中有不同版本的EntityFramework。我的建议是,从所有项目中删除EntityFramework dll,从packages.config中删除关于它的行,然后使用“Install Package EntityFramework”nuget命令重新安装。祝你好运

您是否有对System.Data.Entity的引用(您不应该)?我没有。我确实有一个对System.Web.Entity的引用您需要删除/更新它,这是旧的EntityDataSource控件我删除了该引用。没有任何效果。你确定这就是原因吗?系统。数据是4.0.0.0。我真的很有希望。。注意到我的框架是4.5,并在项目属性中将其切换为4.5.1。。但这并没有解决这个问题:/I我使用的是单个项目解决方案。我还验证了运行时二进制文件中的版本是正确的,所以我提到我在另一台计算机上进行了新安装。我使用的不是SQL CE,而是普通的SQL server数据库。发生在您身上的事情可能是由于Microsoft对sql CE的支持缓慢下降造成的。我查找了您的错误,发现了一个我跳过的建议:EntityFramework.SqlServer。请将此dll添加到项目中,然后重试:(
Could not load type 'System.Data.Entity.Migrations.Model.AlterTableOperation' from assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
Enable-Migrations -ContextTypeName MvcTest.Data.AuditDb
Method not found: 'Void System.Data.Entity.ModelConfiguration.Configuration.EntityMappingConfiguration`1.MapInheritedProperties()