无法找到请求的数据提供者

时间:2017-09-06 12:18:36

标签: c# asp.net asp.net-mvc

所以我制作了一个新的asp .net mvc应用程序,我仍然得到这个错误,

当我运行它然后显示错误“无法找到所请求的.Net Framework数据提供程序”,如果在url中输入id,如“localhost / MVC_Demo / employee / Details / 2” 然后它显示错误...请告诉我如何解决? EmployeeContext.cs文件

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;

namespace MVC_Demo.Models
{
    public class EmployeeContext : DbContext
    {
        public DbSet<Employee> Employee { get; set; }   
    }
}

EmployeeController.cs文件

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MVC_Demo.Models;

namespace MVC_Demo.Controllers
{
    public class EmployeeController : Controller
    {

        public ActionResult Details(int id)
        {
            EmployeeContext employeeContext = new EmployeeContext();
            Employee employee = employeeContext.Employee.Single(emp => emp.ID == id);

            return View(employee);
        }
    }
}

的Web.config

<connectionStrings>
    <add name="EmployeeContext" connectionString="Server=.; database=dbEmployees; Integrated Security=SSPI" providerName="System.Data.Client" />
  </connectionStrings>

Employee.cs文件

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;

namespace MVC_Demo.Models
{
    [Table("Emp")]
    public class Employee
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public string Gender { get; set; }
        public string City { get; set; }
        public int Salary { get; set; }
    }
}

1 个答案:

答案 0 :(得分:1)

这很好用,

<system.data>
    <DbProviderFactories >
        <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
</system.data>