i'm working at an application on web and i'm using ef to create model and accessing to DB.
create session var for use in session level:
private Model.WebsiteModelContainer s_defaultModel; public Model.WebsiteModelContainer DefaultModel { get { s_defaultMode开发者_高级运维l = HttpContext.Current.Session["DefaultModel"] as WebsiteModelContainer; if (s_defaultModel == null) { s_defaultModel = new Model.WebsiteModelContainer(); HttpContext.Current.Session["DefaultModel"] = s_defaultModel; } return s_defaultModel; } }
use DefaultModel in code:
return DefaultModel.Ages.OrderBy(c => c.AgeName).ToList();
After a new build of your project, the first database query executed causes EF to build views that it uses for data access. This can cause a significant delay. You can work around it by having EF pre-compile the views. See How to: Pre-Generate Views to Improve Query Performance from MSDN.
精彩评论