![](/img/trans.png)
[英]Slow updates with Entity Framework 4.3 and SQL Server Compact Edition 3.5
[英]Using SQL Server Compact 4.0.0.1 with Entity Framework 4.3
Could not load System.Data.SqlServerCe.Entity.dll. Reinstall SQL Server Compact.
{"Could not load file or assembly 'System.Data.SqlServerCe.Entity, Version=4.0.0.1, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)":"System.Data.SqlServerCe.Entity, Version=4.0.0.1, Culture=neutral, PublicKeyToken=89845dcd8080cc91"}
創建新的MVC3應用程序
添加Nuget包EntityFramework.SqlServerCompact
<package id="EntityFramework.SqlServerCompact" version="4.1.8482.2" />
創建模型
public class TaskItem { [Key] public int Id { get; set; } public string Description { get; set; } }
創建DbContext
public class TestContext : DbContext { public DbSet<TaskItem> TaskItems { get; set; } }
家庭控制器
public ActionResult Index() { var db = new TestContext(); // breakpoint on Add() below db.TaskItems.Add(new TaskItem { Description = "Get shit done."}); return View(); }
Web.config連接字符串和運行時以及System.Data
<add name="ApplicationServices" connectionString="Data Source=|DataDirectory|Test.sdf" providerName="System.Data.SqlServerCe.4.0" />
<runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Data.SqlServerCe" publicKeyToken="89845dcd8080cc91" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.0.0.1" newVersion="4.0.0.1" /> </dependentAssembly> </assemblyBinding> </runtime> <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>
Web.config都是默認的......這里沒什么好玩的......所有的DLL都是本地復制和bin ...我錯過了什么? 它必須非常簡單。
從web.config中刪除Dependent Assembly部分解決了這個問題,但我仍然需要解釋為什么要關閉答案。
從web.config中刪除依賴程序集綁定
<dependentAssembly>
<assemblyIdentity name="System.Data.SqlServerCe" publicKeyToken="89845dcd8080cc91" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.1" newVersion="4.0.0.1" />
</dependentAssembly>
檢查是否在項目中創建了此代碼
EntityFramework.SqlServerCompact.cs under the App_Start folder
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
[assembly: WebActivator.PreApplicationStartMethod(typeof(MyStory.Tests.App_Start.EntityFramework_SqlServerCompact), "Start")]
namespace MyStory.Tests.App_Start {
public static class EntityFramework_SqlServerCompact {
public static void Start() {
Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0");
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.