27

I want to set command timeout for query execution, currently I am doing context.Database.CommandTimeout = 90; but i feel this is not working, I tried checking the process logs in database but found the time difference was always less than 90sec.

Can someone help how can I set the database timeout in Entity Framework 6?

Ali
  • 427
  • 1
  • 4
  • 14

1 Answers1

63

Check this :

Entity Framework 6 :

this.context.Database.CommandTimeout = 180;

Entity Framework 5:

((IObjectContextAdapter)this.context).ObjectContext.CommandTimeout = 180;

Entity Framework 4 and below:

this.context.CommandTimeout = 180;
er-sho
  • 9,581
  • 2
  • 13
  • 26
Dilip Oganiya
  • 1,504
  • 12
  • 20
  • Thanks. That fixed many occurrences of this build error for me: Upgrading from Entity Framework 5 to EF6 Error BC30456 "'CommandTimeout' is not a member of" – Zeek2 Feb 22 '21 at 10:15
  • 2
    For EF 6.2 at least this needs to be placed in Configuration class in the migrations folder in the constructor: public Configuration(){ CommandTimeout = 3600; } – T M Jul 13 '21 at 17:35