我知道我可能有点厚,但是......
首先使用 EF 代码创建了一个新的 MVC3 测试应用程序。
语境:
public class EmployeeContext : DbContext
{
public DbSet<Employee> Employees { get; set; }
}
控制器:
public ActionResult Index()
{
List<Employee> employees;
using (var ctx = new EmployeeContext())
{
employees = ctx.Employees.ToList();
}
return View(employees);
}
[HttpPost]
public ActionResult Create(Employee employee)
{
using (var ctx = new EmployeeContext())
{
ctx.Employees.Add(employee);
ctx.SaveChanges();
}
return RedirectToAction("Index");
}
正如预期的那样,EF 创建了数据库,我可以创建并列出一个员工。
现在为 miniprofiler。
从 nuget 添加了 miniprofiler.EF 1.9.1。
我想我只需要将以下行添加到 global.asax application_start 方法:
MiniProfilerEF.Initialize();
当我使用它运行时,我得到一个“无法确定'System.Data.SqlClient.SqlConnection'类型的连接的提供程序名称。” 例外。
我不必在 web.config 中添加任何内容,对吗?