Set Command Timeout in EF 6
Asked Answered
T

1

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?

Tonne answered 2/5, 2016 at 8:17 Comment(1)
Follow this post for more clarity: https://mcmap.net/q/86651/-entity-framework-timeoutsGraehme
G
66

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;
Graehme answered 2/5, 2016 at 9:10 Comment(2)
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"Selfinterest
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; }Trifocals

© 2022 - 2024 — McMap. All rights reserved.