So, I'm writing this code to Execute a stored procedure which is getting timed out in 30 seconds (which after some search I understood as the default value). When I searched for a way to increase the CommandTimeout, I got many answers which recommends using IObjectContextAdapter Interface to set the timeout something like this :
((IObjectContextAdapter)this).ObjectContext.CommandTimeout = 300;
When I checked the context object, I found the CommandTimeout property inside the Database object and when I wrote the following code, everything works fine and the timeout is increased to what I have set:
public MyContext() :
base("name=MyContext")
{
Database.SetInitializer<MyContext>(null);
Database.CommandTimeout = 300;
}
I wanted to know if there are any issues setting the CommandTimeout this way or is the IObjectContextAdapter method recommended.
Thanks in advance.