1

I have an application in which I used Entity framework 6. I have this snippet :

            Action empBasicAction;
            Console.WriteLine("Loading context1 ......");
            empBasicAction = () => { Model1 contexte = new Model1(); };
            Console.WriteLine("end of loading, time = " + CalculateTime(empBasicAction));
            Console.WriteLine("Loading context2 ......");
            empBasicAction = () => { Model1 contexte = new Model1(); };
            Console.WriteLine("end of loading2, time = " + CalculateTime(empBasicAction));
            Console.WriteLine("Selection1......");
            empBasicAction = () =>
            {
                Model1 contexte1 = new Model1();
                contexte1.aspnet_Users.Count();
            };

            Console.WriteLine("end selection, time= " + CalculateTime(empBasicAction));

            Console.WriteLine("Selection2   ......");
            empBasicAction = () =>
            {
                Model1 contexte1 = new Model1();
                contexte1.aspnet_Users.Count();
            };
            Console.WriteLine("end selection2, time = " + CalculateTime(empBasicAction)); 

with this method :

public static long CalculateTime(Action t)
        {
            Stopwatch alarme = new Stopwatch();
            alarme.Start();
            t();
            alarme.Stop();
            return alarme.ElapsedMilliseconds;

        } 

I get as output :

Loading context1 ...... 
end of loading, time = 445
 Loading context2...... 
end of loading2, time = 0
 Selection1...... 
end selection1, time= 7203
 Selection2...... 
end selection2, time = 9

I don't understand the output result meanings : I mean :

  1. What are the reasons of the first output :why it takes 445 ms to instanciate a DbContext? and why , then, it takes 0 ms !!
  2. For the selection operation, Why it costs 7 seconds !! and then only 9 ms

Can you help me ,

Thanks,

Lamloumi Afif
  • 8,941
  • 26
  • 98
  • 191
  • 1
    Duplicate question , you can find the answer here [Entity framework very slow to load for first time after every compilation](http://stackoverflow.com/questions/30423838/entity-framework-very-slow-to-load-for-first-time-after-every-compilation) – Ehsan Feb 12 '16 at 15:30
  • http://neverindoubtnet.blogspot.com/2012/03/squash-entity-framework-startup-time.html – Steve Greene Feb 12 '16 at 16:39

0 Answers0