public void Invoke(TModel model) { var parameters = BindingModelPropertyToParameter( model, _strategy.GetModelPropertyBindings(), _strategy.GetDbParameters()).ToList(); try { _serviceProvider.Open(); if (_serviceProvider.RunStoredProc(_strategy.GetDbProcName(), parameters) == 0) { throw new DbOperationException( "ERROR_SQL_PROCEDURE_EXECUTION_FAILED", _strategy.GetDbProcName(), parameters); } } catch (Exception exception) { throw new DbOperationException( "ERROR_SQL_PROCEDURE_EXECUTION_FAILED", exception, _strategy.GetDbProcName(), parameters); } finally { _serviceProvider.Close(); } }
public void Empty() { var queryStrategyProvider = _container.Resolve <IDbQueryStrategyProvider>(); var strategy = queryStrategyProvider.GetEmptyStrategy(_modelStrategy); _serviceProvider.Open(); _serviceProvider.Execute(strategy.GetDbQueryScript(), new List <IDbDataParameter>()); _serviceProvider.Close(); }
public bool Any(Expression <Func <TModel, object> > specifierExpression) { var queryStrategyProvider = _container.Resolve <IDbQueryStrategyProvider>(); var filterExpressions = new List <DbQueryWhereClause <TModel> >() { new DbQueryWhereClause <TModel>() { Clause = specifierExpression, Operator = DbQueryConditionOperators.And } }; var strategy = queryStrategyProvider.GetSelectAggregationStrategy( ModelStrategy, DbQueryAggregateMode.Any, filterExpressions); var sql = strategy.GetDbQueryScript(); var dbparams = strategy.GetDbParameters().ToList(); _serviceProvider.Open(); IDataReader reader = null; bool isAny; try { reader = _serviceProvider.QueryGetReader(sql, dbparams); isAny = reader.Read(); } catch (Exception exception) { throw new DbOperationException("ERROR_SQL_EXECUTION_FAILED", exception, sql, dbparams); } finally { reader?.Close(); _serviceProvider.Close(); } return(isAny); }
public void Dispose() { if (_provider.IsConnectionOpen()) { _provider.Close(); } _provider.Dispose(); }
public int Delete(IEnumerable <TModel> models, bool throwIfAnyModelFailed = true) { int success = 0; var queryStrategy = _queryStrategyProvider.GetDeleteStrategy <TModel>(_queryTable.ModelStrategy); var sql = queryStrategy.GetDbQueryScript(); var dbparams = queryStrategy.GetDbParameters(); var exceptions = new List <DbOperationException>(); _serviceProvider.Open(); foreach (var model in models) { DbModelBindingHelper.BindingModelToParameters( model, _queryTable.ModelStrategy.PropertyStrategies, dbparams); try { if (_serviceProvider.Execute(sql, dbparams) > 0) { success++; } else { exceptions.Add(new DbOperationException("ERROR_SQL_EXECUTION_FAILED", sql, dbparams)); } } catch (Exception ex) { exceptions.Add(new DbOperationException("ERROR_SQL_EXECUTION_FAILED", ex, sql, dbparams)); } } _serviceProvider.Close(); if (throwIfAnyModelFailed) { throw new DbMultipleOperationsException(exceptions); } return(success); }