Six seconds warmup time for the first entity framework 6 nonquery

entity-framework entity-framework-6


From my integration test:

// Act
Stopwatch w = new Stopwatch();

public void Create(UserDTO userDTO)
    var user = userDTO.ToEntity();
    _context.Entry(user).State = EntityState.Added;

6,2 seconds to do an "sql insert" is crazy. I already see the application users complaining when they first open a project which they use the whole year. So everyday they have to wait 6 seconds...

I thought the warm up time in EF6 has improved?

Is there anything I can do to improve this miserable behavior?

12/13/2013 11:42:21 AM

Accepted Answer

Try EF6 CodeFirst View Generation T4 Template for C#. Pre-generated views improve application start-up time by moving the work that would have to be done at runtime to design time. more info

12/13/2013 6:19:09 PM

Popular Answer

The time is not spent to insert a simple data. EF creates the model in the memory, that is where the time you spent goes.

EF creates Entity Data Model and executes View Generation(not db views) for the first time you do an operation on context. Have a look at this blog post.

Take a look here to improve the performance by using pre-generated views to decrease model load time.

To improve the performance you can initialize your context async when you start your application. Beware the multithreading issues.

using (var context = new MyContext())

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow