Пример #1
0
        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();
            }
        }
Пример #2
0
        public void Empty()
        {
            var queryStrategyProvider = _container.Resolve <IDbQueryStrategyProvider>();
            var strategy = queryStrategyProvider.GetEmptyStrategy(_modelStrategy);

            _serviceProvider.Open();
            _serviceProvider.Execute(strategy.GetDbQueryScript(), new List <IDbDataParameter>());
            _serviceProvider.Close();
        }
Пример #3
0
        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);
        }
Пример #4
0
        public void Dispose()
        {
            if (_provider.IsConnectionOpen())
            {
                _provider.Close();
            }

            _provider.Dispose();
        }
Пример #5
0
        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);
        }