EntityFramework-Reverse-POCO-Code-First-Generator icon indicating copy to clipboard operation
EntityFramework-Reverse-POCO-Code-First-Generator copied to clipboard

Added a configurable CommandTimeout setting

Open Darrenthebrit opened this issue 9 years ago • 3 comments

Hi,

I have tried creating a pull request and have been unsuccessful; very good chance that I am not doing it correctly :)

We have experienced some long running stored procedures. When this happens, we typically have to apply a Database.CommandTimeout to the DbContext; this is not definable in the connection string.

To facilitate this I have added a setting into the Database.tt file to allow setting the command timeout.

This is then utilized by the EF.Reverse.POCO.Core.ttinclude and EF.Reverse.POCO.ttinclude files

Perhaps you can make use of the change in a future revision?

Changes were:

Line 17 of Database.tt

DbCommandTimeout = 60; // sets the DbContext.Database.CommandTimeout property. If 0 then it will be ignored.

Line 37 of EF.Reverse.POCO.Core.ttinclude

int DbCommandTimeout = 0;

And this, added into each of the of the DbContext constructors; around lines 240, 249, 258,267,276 of EF.Reverse.POCO.ttinclude (I didn't add it to the Fake DbContext)

<#if(DbCommandTimeout > 0) {#>    this.Database.CommandTimeout = <#=DbCommandTimeout#>;
<#}#>

Darrenthebrit avatar May 11 '17 18:05 Darrenthebrit

The correct way to do this is to set MakeClassesPartial = true; then create a partial db context, and override the InitializePartial(); function to set anything you want, including the command timeout.

sjh37 avatar May 12 '17 15:05 sjh37

Let me know if you want this re-opened, or if there are other issues.

sjh37 avatar May 12 '17 15:05 sjh37

Ah, ok, perfect; didn't think of that :)

Thanks!

Darrenthebrit avatar May 12 '17 19:05 Darrenthebrit