开发者

why EF takes a long time in first called method

开发者 https://www.devze.com 2023-03-22 09:25 出处:网络
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:

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

精彩评论

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