private void ExecuteModelDbOperation(IDbQueryStrategy strategy, TModel model = null) { Exception exception = null; var dbparams = (model == null) ? new List <IDbDataParameter>() : DbModelBindingHelper.BindingModelToParameters(model, ModelStrategy.PropertyStrategies, strategy.GetDbParameters()); _serviceProvider.Open(); try { if (_serviceProvider.Execute(strategy.GetDbQueryScript(), dbparams) == 0) { throw new DbChangeNoAffectException(); } } catch (Exception ex) { exception = ex; } _serviceProvider.Close(); if (exception != null) { throw new DbAggregateException(exception); } }
private void ExecuteModelDbOperation(IDbQueryStrategy strategy, IEnumerable <TModel> models) { var exceptions = new Dictionary <int, Exception>(); _serviceProvider.Open(); _serviceProvider.BeginTransaction(); var modelIdx = 0; foreach (var model in models) { try { var dbparams = DbModelBindingHelper.BindingModelToParameters( model, ModelStrategy.PropertyStrategies, strategy.GetDbParameters()); if (_serviceProvider.Execute(strategy.GetDbQueryScript(), dbparams) == 0) { throw new DbChangeNoAffectException(); } } catch (Exception ex) { exceptions.Add(modelIdx, ex); } modelIdx++; } if (!exceptions.Any()) { _serviceProvider.Commit(); _serviceProvider.Close(); } else { _serviceProvider.Rollback(); _serviceProvider.Close(); throw new DbAggregateException(exceptions); } }