我有一个数据库表,包括{EmployeeId,name,city,gender}。我想检索它们并在视图中显示它..但是获得
的例外“基础提供商失败了”
我的模特:
[Table("tblEmployee")]
public class Employee
{
public int EmployeeId { get; set; }
public string Name { get; set; }
public string Gender { get; set; }
public string City { get; set; }
}
public class EmployeeContext:DbContext
{
public DbSet<Employee> Employees { get; set; }
}
我的控制员:
public class EmployeeController : Controller
{
public ActionResult Details(int id)
{
EmployeeContext employeeContext=new EmployeeContext();
Employee aEmployee= employeeContext.Employees.Single(emp => emp.EmployeeId == id);
return View(aEmployee);
}
}
global.asax中:
Database.SetInitializer<MvcPragim.Models.EmployeeContext>(null);
的ConnectionString:
<add name="EmployeeContext"
connectionString="Server=ASUS- PC\SQLEXPRESS; Database=mvc_db; User Id=sa; password=1234;Integrated Security=True; MultipleActiveResultSets=True;"
providerName="System.Data.SqlClient" />
问题很重要......提前完成
答案 0 :(得分:0)
1.使用nUGet安装实体框架 2.控制器的名称和连接字符串名称不匹配。在连接字符串中粘贴控制器名称。