Entity framework 在N层框架中使用MiniProfiler
我有一个使用BLL和DAL的MVC4Web应用程序。DAL使用EF6和模型优先方法。我想设置MiniProfiler来分析web和数据库调用。我通过Nuget添加了MiniProfiler和MiniProfiler.MVC4,并在网站上运行 我的问题是,如何设置BLL和DAL以返回带有查询信息的EF调用 以下是项目的设置方式: Web层-参考MiniProfiler、MiniProfiler.MVC和BLL项目。控制器调用BLL方法 BLL-参考MiniProfiler和DAL项目。BLL方法调用DAL方法 DAL-参考MiniProfiler和MiniProfiler,EF5。DAL方法使用Linq调用数据库Entity framework 在N层框架中使用MiniProfiler,entity-framework,mvc-mini-profiler,Entity Framework,Mvc Mini Profiler,我有一个使用BLL和DAL的MVC4Web应用程序。DAL使用EF6和模型优先方法。我想设置MiniProfiler来分析web和数据库调用。我通过Nuget添加了MiniProfiler和MiniProfiler.MVC4,并在网站上运行 我的问题是,如何设置BLL和DAL以返回带有查询信息的EF调用 以下是项目的设置方式: Web层-参考MiniProfiler、MiniProfiler.MVC和BLL项目。控制器调用BLL方法 BLL-参考MiniProfiler和DAL项目。BLL方法调
基于这个设置,我可以从BLL获取MiniProfiler数据,但我没有获取任何EF SQL数据 好吧,我想好了。以下是如何设置N层项目以支持MiniProfiler: Web层-添加对MiniProfiler、MiniProfiler.MVC、MiniProfiler.EntityFramework和BLL项目的引用。在Global.asax中,确保启用EF评测:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
// Entity Framework Profiling
MiniProfilerEF.Initialize();
}
以下是一个控制器通过分析调用BLL的示例:
[HttpGet]
public ActionResult Index()
{
var profiler = MiniProfiler.Current;
using (profiler.Step("Web Controller"))
{
Employee bll = new Employee();
int value = bll.GetLastEmployeeID();
}
return View();
}
public int GetLastEmployeeID()
{
int result = 0;
var profiler = MiniProfiler.Current;
using (profiler.Step("BLL - GetLastEmployeeID"))
{
EmployeeDAO dao = new EmployeeDAO();
result = dao.GetLastEmployeeID();
}
return result;
}
BLL-添加对MiniProfiler和DAL项目的引用。BLL方法调用DAL方法
下面是一个通过分析调用DAL的BLL方法示例:
[HttpGet]
public ActionResult Index()
{
var profiler = MiniProfiler.Current;
using (profiler.Step("Web Controller"))
{
Employee bll = new Employee();
int value = bll.GetLastEmployeeID();
}
return View();
}
public int GetLastEmployeeID()
{
int result = 0;
var profiler = MiniProfiler.Current;
using (profiler.Step("BLL - GetLastEmployeeID"))
{
EmployeeDAO dao = new EmployeeDAO();
result = dao.GetLastEmployeeID();
}
return result;
}
DAL-添加对MiniProfiler和MiniProfiler的引用,EF5。DAL方法使用Linq调用数据库。例如:
public int GetLastEmployeeID()
{
int id = 0;
using (var context = new CompanyEntities())
{
var lastEmployee = (from e in context.Employees
where e.IsDeleted == false
orderby e.EmployeeID descending
select e).First();
id = lastEmployee.EmployeeID;
}
return id;
}
使用此设置,我可以使用SQL获取EF评测,以显示在网站上的MiniProfiler中。如何从BLL到DAL进行通信?是通过网络服务吗?更新了说明。如果你还需要什么,请告诉我。