I know I am probably being a bit thick however……
Created a new MVC3 test application using EF code first.
Context:
public class EmployeeContext : DbContext
{
public DbSet<Employee> Employees { get; set; }
}
Controller:
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");
}
As expected, EF creates the database and I can create and list an employee.
Now for miniprofiler.
Added miniprofiler.EF 1.9.1 from nuget.
I think i just need to add the following line to the global.asax application_start method:
MiniProfilerEF.Initialize();
When I run using this, I get a “Unable to determine the provider name for connection of type ‘System.Data.SqlClient.SqlConnection’.” exception.
I do not have to add anything to the web.config right?
No, you’re not thick :-). There appears to be problem with EF and MiniProfiler.EF 1.9.1. See this question. Apparently, there will a workaround in version 2.0.