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 :
- What are the reasons of the first output :why it takes 445 ms to instanciate a DbContext? and why , then, it takes 0 ms !!
- For the selection operation, Why it costs 7 seconds !! and then only 9 ms
Can you help me ,
Thanks,