c# - Temporarily set DbContext's CommandTimeout -
I know that for some queries, I can set some command timeout of DBCTNX like this:
Public category YourContext: DbContext {public: Get your ObjectContext related to Base ("YourConnectionString") {// this DbContext var objectContext = (as in this IObjectContextAdapter). Objectcontext; // sets the command timeout for all commands that default 30 seconds object contact. Comma timeout = 120; }}However, I want to keep default 30 seconds, except for a single method, which takes a little longer time.
I question this single question?
I tried to use:
There was another reason to use public zero doSomething () {//, but in this case also it is using the / dbContext While doing (IMIDBCTXTA = Representative DBCCTX) (using (IOBJxtTextAdapter) DD) Object Contex Comma timeout = 120; ... // myQuery}}
Everything works perfectly, as long as I have my Doc-DB restrict (and yes, I duplicate my representative - Code> InvalidCastException returns:
System.InvalidCastException: Unable to remove object type 'Castle.Proxies.FakeMyDbContextProxy' to type 'System.Data.Entity.Infrastructure' .IObjectContextAdapter '.
That's because you depend on the details of the implementation ( The fact is that your will come MIDBContax
also implements IObjectContextAdapter
) that you should not know about this. In your unit test, the IMyDbContext
example is actually a proxy generated by the funny framework , And does not apply to IObjectContextAdapter
.
Since the command timeout
is not understood for this duplicate DBCTTtex
I suggest that if the artist is successful, then you will be given the commandtime Try inserting and setting up the cam
var using the DB in the form of the VastuConttexAdapter = IObjectContextAdapter; If (objectContextAdapter! = Null) objectContextAdapter.ObjectContext.CommandTimeout = 120;
In this way, command timeout will be set in the actual execution environment, but not in the unit test (which does not make any difference to it, in fact, a better and cleaner The option
IMyDbContext
will be modified to highlight how to set CommandTimeout
.
Code>:
Interface IMIDB Contex {... int commandtimeout {get} set;}} class MyDbContext: IMyDbContext {... public int commandtimeout {acquaints} Objective Context.CommandTimeout;} Set {{(IObjectContextAdapter) this.) Object Context.CommandTimeout = Value;}}}
And now you just do this Can: db.CommandTimeout = 120;
without worrying about the actual type of reference
Witty structure for this property Will generate a dummy implementation.
Comments
Post a Comment