keyur

keyur

  • NA
  • 363
  • 0

Entity Framework

Feb 12 2015 3:40 AM
Hello


When I first call using entity framework like
context.Employee.FirstOrDefault() it will take about 50 to 60 seconds and from second call it will take only 2 to 3 seconds


how do i reduce this.? I already created precomplied view but it did not work


can anyone help in this?

Answers (7)

0
Jignesh Trivedi

Jignesh Trivedi

  • 0
  • 62.3k
  • 46m
Feb 12 2015 6:14 AM
Accepted Answer
0
Jignesh Trivedi

Jignesh Trivedi

  • 0
  • 62.3k
  • 46m
Feb 12 2015 7:06 AM
Now you can make dummy call to web service method that intialization your entity framework...
hope this will help you.
0
keyur

keyur

  • 0
  • 363
  • 0
Feb 12 2015 7:02 AM
Hello 

Thansk for this,but i already made Custom factory for intialization and it works.
Can we check context is intialized or not ?
0
keyur

keyur

  • 0
  • 363
  • 0
Feb 12 2015 5:51 AM
Hi Jignesh


Yes you are right. I major all factors like when I call service method to reach method it take about 10 seconds and then when i call EF query to get only one data it takes about 40 seconds


so I just want to reduce EF calling time. and yes i tried to use Global.asax file but it will not called anytime.So I made custom host factory and write code there for intialiazation but then problem in that when my service idel it will not call again hostfactory.


I think Global.asax is good idea but its not called any idea why ?


thanks for the quick response
0
Jignesh Trivedi

Jignesh Trivedi

  • 0
  • 62.3k
  • 46m
Feb 12 2015 5:46 AM

Hi,

I think In your case

First Call time = first connection time to web service+ initilization of EF + generating SQL Query + SQL server prepair statics for your query + Execution time of query :)

yes you can write warm up process (it is nothing but simple method which call your web service method) which is run at application start event of Global.asax.....

so whenever your iis is reset application start event of Global.asax call first and it will make initialization process....

hope this will help you.

0
keyur

keyur

  • 0
  • 363
  • 0
Feb 12 2015 5:37 AM
Hello Jignesh


thanks for the answer.

I am using EF 5.0. I have generated precompiled view but it will not helpful.


Basically I have webservice and when my first call take place using EF it will take about 1 minute and after each call taking 2 to 3 seconds.so i have to reduce first call. or if that not possible then have to do some mechnisam to intialize context before service initalized


I do not have much idea in EF


Can you please help this ?
0
Jignesh Trivedi

Jignesh Trivedi

  • 0
  • 62.3k
  • 46m
Feb 12 2015 5:32 AM

Hi,

First time execution include time to generate native code for EF base dll and generate equvallent SQL.

When you execute Linq to entity query first time Entity framework base dll is  generate the native code and you can improve the start up performace by using NGen.exe

Please refer my article:
http://www.c-sharpcorner.com/UploadFile/ff2f08/entity-framework-6-0-ngen-exe-and-startup-performance/

By the way which Entity Framework version you are working with?

hope this will help you.