public TResult ExecuteCommand <TResult> (Func <IRepositoryLocator, TResult> command) //where TResult : class, Common.Message.IDtoResponseEnvelop { try { BeginTransaction(); LoggingFactory.LogDebug("Begin Transaction"); var result = command.Invoke(Locator); CommitTransaction(); LoggingFactory.LogDebug("Commit Transaction"); CheckForWarnings(result); return(result); } catch (BusinessException exception) { if (IsInTranx) { Rollback(); LoggingFactory.LogDebug("Rollback Transaction"); } var type = typeof(TResult); var instance = Activator.CreateInstance(type, true) as IDtoResponseEnvelop; if (instance != null) { instance.Response.AddBusinessException(exception); LoggingFactory.LogException(instance.Response.BusinessException.ToString(), exception); } return((TResult)instance); //as TResult; } catch (Exception ex) { LoggingFactory.LogException(ex.Message, ex); throw ex; } }