Entity Framework Slow first query RRS feed

  • Question

  • User1029764681 posted

    So my EDMX has roughly 60-70 tables/stored procs.  The first time I load my application after it is published to the server its slow.  Once that section has been viewed once.. the application is much faster.

    I found this link and added this to my solution. 

     public class MyDbConfiguration : DbConfiguration
            public MyDbConfiguration() : base()
                var path = Path.GetDirectoryName(this.GetType().Assembly.Location);
                SetModelStore(new DefaultDbModelStore(path));


    However, it still seems slow and I feel like I am missing a step.  What has everyone else done?  All my google searches point back to this same type of solution.

    Thursday, August 15, 2019 5:07 PM

All replies

  • User1120430333 posted
    Performance considerations
    Friday, August 16, 2019 12:05 AM
  • User1520731567 posted

    Hi fmrock164,

    It seems that only this method is currently being promoted.

    What is your EF version?

    I suggest to use EF 6.2,you can use a Model Cache which loads a prebuilt edmx when using code first;

    If is earlier version,here are three suggestions mentioned in this post:

    • Using a Cached DbModelStore
    • Generate pre-compiled Views
    • Generate pre-compiled version of entity framework using NGen to avoid jitting

    If you still feel very slow,I suggest you could find the reason by F12 performance or optimize sql algorithm, and optimize query statement...

    Best Regards.

    Yuki Tao

    Friday, August 16, 2019 2:44 AM
  • User1029764681 posted


    I am using 6.2.  Is there a setting to load a prebuilt edmx. I feel like I have missed a step. I see no EDMX file on the server.  

    How do I know if the pre-built edmx is actually being built?

    Friday, August 16, 2019 11:49 AM
  • User283571144 posted

    Hi fmrock164, 

    As far as I know, the model cache which loads a prebuilt edmx when using code first not database first.

    If you want to speed up Entity Framework, I suggest you could refer to below ways:

    1.Turn off the LazyLoading (EDMX =>  right click the UI => properties => Lazy Loading Enabled set it to false)

    2.Split your Edmx into many smaller, only include the ones you need in your page. 

    Best Regards,


    Monday, September 2, 2019 9:05 AM