2017-09-06 34 views
0

所以我做了一個新的ASP.NET MVC應用程序,只是我仍然得到這個錯誤,無法找到所請求的數據提供

當我運行它,然後顯示錯誤「無法找到請求的.NET Framework數據提供「,如果輸入id像」本地主機/ MVC_Demo /員工/詳細/ 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; } 
    } 
} 
+0

此鏈接可能會有所幫助。 https://stackoverflow.com/questions/9928361/unable-to-find-the-requested-net-framework-data-provider-in-visual-studio-2010 –

回答

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> 
+0

但我的SQL Server 2014數據庫,所以現在? –

+0

無法找到請求的.Net Framework數據提供程序。它可能沒有安裝。 源錯誤: 第14行:{ 線15:EmployeeContext employeeContext =新EmployeeContext(); 第16行:Employee employee = employeeContext.Employee.Single(emp => emp.ID == id); 第17行:// Employee employee = new Employee(); 第18行:// { –

+0

現在它顯示上述錯誤 –

相關問題