无法找到请求的.net数据提供商

时间:2015-10-13 19:58:45

标签: c# sql-server asp.net-mvc entity-framework asp.net-mvc-4

我无法弄清楚如何处理此异常,并希望得到帮助。我基本上有我创建的SQL CE数据库。我还创建了一个表和数据。 然后我想在ASP MVC4项目中使用Entity框架从该表加载数据。 这是我的代码和Web配置,但我得到如下所述的异常(见图)

控制器:

 public class EmployeeController : Controller
 {
        //
        // GET: /Employee/

        public ActionResult Index()
        {

            EmployeeContext e = new EmployeeContext();
            var list = e.Employeeslist.ToList(); // here is the exception

模型类:

 public class EmployeeContext: DbContext
 {
        public DbSet<Employee> Employeeslist { get; set; }
 }

[Table("Employees")]
public class Employee
{
    public int ID { get; set; }
    public string Name { get; set; }
    public string Gender { get; set; }
    public string City { get; set; }
}

我的连接字符串

 <connectionStrings>
    <add name="EmployeeContext" connectionString="Data Source=c:\users\g\documents\visual studio 2012\Projects\TestMVCApp\TestMVCApp\App_Data\EmployeeDB.sdf" providerName="System.Data.SqlServerCe.4.0" />
  </connectionStrings>

这是我得到的例外: enter image description here

我还从实体框架的nuget包EntityFramework.SqlServerCompact包安装但是我仍然得到这个例外。任何帮助表示赞赏!

此处还有来自网络配置的一些数据:

<entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="System.Data.SqlServerCe.4.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" />
    </providers>
  </entityFramework>

还有警告(提供商的蓝线 - 不确定是警告还是什么)说entityFramework有关于providers的无效子节点。

1 个答案:

答案 0 :(得分:0)

安装SQL Server CE运行时。对于使用此库,可能需要部分必须在GAC中,而不仅仅是您的项目。

http://www.microsoft.com/en-us/download/details.aspx?id=17876

相关问题