.net - Using Entity Framework and Transient Fault Handling Block WITHOUT Azure -


i have several apps rely on repository using ef 4. sometimes, sql operation fail because (i.e. timeout, failed connection, etc.).

i want use transient fault handling application block, not using azure. there seems proliferation of info out there azure scenarios, no info on using "barebones" approach. worry if use azure detection strategies, won't work.

anyone know can find info on how best use this?

i able started looking here: http://hmadrigal.wordpress.com/2012/04/23/automatic-retries-using-the-transient-fault-handling-from-enterprise-libraries-entlib/

you have write own detection strategy class. in case looks this:

public class entityframeworktransienterrordetectionstrategy : itransienterrordetectionstrategy {     #region itransienterrordetectionstrategy members      public bool istransient(exception ex)     {         if (ex sqlexception)         {             return true;         }         else             return false;     }      #endregion } 

in repository constructor have this:

_retrystrategy = new fixedinterval(_retrylimit, new timespan(0, 0, 0, 0, 500));         _retrypolicy = new retrypolicy<entityframeworktransienterrordetectionstrategy>(_retrystrategy);     // use our custom detection strategy          _retrypolicy.retrying += (sender, args) =>             {                 // log retries warnings                 _logger.warnformat("retry {0} of {1} due exception: {2}", args.currentretrycount, _retrylimit, args.lastexception);             }; 

a typical repository method:

public override harvesterdomain.source selectsource(guid id)     {         harvesterdomain.source source = null;         _retrypolicy.executeaction(() =>             {                 var contextsource = _context.sources.where(s => s.id == id).firstordefault();                  if (contextsource != null)                     source = contextsource.toharvesterdomainsource();             });         return source;     } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -