开发者

why EF takes a long time in first called method

i'm working at an application on web and i'm using ef to create model and accessing to DB.

  1. 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;
        }
    }
    
  2. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜