/// <summary> Deletes all the <typeparamref name="TEntity"/> records by given IDs. </summary>
        ///
        /// <typeparam name="TEntity"> Type of the entity. </typeparam>
        /// <param name="ids"> The identifiers of records. </param>
        ///
        /// <returns> Number of rows affected (integer) </returns>
        public int DeleteAll <TEntity>(IEnumerable <long> ids)
            where TEntity : class
        {
            OracleTransaction transaction = null;
            int result = 0;

            using (transaction = SimpleAccess.BeginTrasaction())
            {
                try
                {
                    var entityInfo  = RepositorySetting.GetEntity2Info(typeof(TEntity));
                    var commandText = string.Format("{0}_Delete", entityInfo.DbObjectName);

                    foreach (var id in ids)
                    {
                        result += SimpleAccess.ExecuteNonQuery(transaction, commandText, CommandType.StoredProcedure, new[] { OracleParametersExtensions.ToDataParam(id, (string)"Id") });
                    }
                }

                catch (Exception)
                {
                    SimpleAccess.EndTransaction(transaction, false);
                }
            }

            return(result);
        }
        /// <summary> Delete All records from the table with a transaction. </summary>
        ///
        /// <typeparam name="TEntity"> Type of the entity. </typeparam>
        /// <param name="transaction"> The SQL transaction. </param>
        ///
        /// <returns> Number of rows affected (integer) </returns>

        public int DeleteAll <TEntity>(OracleTransaction transaction) where TEntity : class
        {
            var entityInfo  = RepositorySetting.GetEntity2Info(typeof(TEntity));
            var commandText = string.Format("{0}_DeleteAll", entityInfo.DbObjectName);

            return(SimpleAccess.ExecuteNonQuery(transaction, commandText, CommandType.StoredProcedure));
        }
        /// <summary> Deletes all the <typeparamref name="TEntity"/> records by  objects as OracleParameter names and values. </summary>
        ///
        /// <typeparam name="TEntity"> Type of the entity. </typeparam>
        /// <param name="paramObjects"> The <![CDATA[IEnumerable<object>]]> objects as parameters. </param>
        ///
        /// <returns> Number of rows affected (integer) </returns>
        public int DeleteAll <TEntity>(IEnumerable <object> paramObjects)
            where TEntity : class
        {
            OracleTransaction transaction = null;
            int result = 0;

            using (transaction = SimpleAccess.BeginTrasaction())
            {
                try
                {
                    var entityInfo  = RepositorySetting.GetEntity2Info(typeof(TEntity));
                    var commandText = string.Format("{0}_Delete", entityInfo.DbObjectName);

                    foreach (var paramObject in paramObjects)
                    {
                        result += SimpleAccess.ExecuteNonQuery(transaction, commandText, CommandType.StoredProcedure, SimpleAccess.BuildOracleParameters(paramObject));
                    }
                    SimpleAccess.EndTransaction(transaction);
                }

                catch (Exception)
                {
                    SimpleAccess.EndTransaction(transaction, false);
                }
            }

            return(result);
        }
        /// <summary> Updates all the given entities. </summary>
        ///
        /// <typeparam name="TEntity"> Type of the entity. </typeparam>
        /// <param name="entities"> The <![CDATA[IEnumerable<TEntity>]]> to update </param>
        ///
        /// <returns> Number of rows affected (integer) </returns>
        public int UpdateAll <TEntity>(IEnumerable <TEntity> entities)
            where TEntity : class
        {
            OracleTransaction transaction = null;
            int result = 0;

            using (transaction = SimpleAccess.BeginTrasaction())
            {
                try
                {
                    var    entityInfo  = RepositorySetting.GetEntity2Info(typeof(TEntity));
                    string commandText = string.Format("{0}_Update", entityInfo.DbObjectName);

                    foreach (var entity in entities)
                    {
                        var entityParameters = entityInfo.GetUpdateParameters(entity);

                        result += SimpleAccess.ExecuteNonQuery(transaction, commandText, CommandType.StoredProcedure
                                                               , entityParameters.DataParametersDictionary.Values.ToArray());

                        entityParameters.LoadOutParametersProperties(entity);
                    }
                    SimpleAccess.EndTransaction(transaction);
                }
                catch (Exception)
                {
                    SimpleAccess.EndTransaction(transaction, false);
                }
            }
            return(result);
        }
        /// <summary> Deletes the given ID. </summary>
        ///
        /// <typeparam name="TEntity"> Type of the entity. </typeparam>
        /// <param name="transaction"> The SQL transaction. </param>
        /// <param name="oracleParameters"> Options for controlling the SQL. </param>
        ///
        /// <returns> . </returns>
        public virtual int Delete <TEntity>(OracleTransaction transaction, params OracleParameter[] oracleParameters)
            where TEntity : class
        {
            //var name = typeof(TEntity).Name;
            var entityInfo  = RepositorySetting.GetEntity2Info(typeof(TEntity));
            var commandText = string.Format("{0}_Delete", entityInfo.DbObjectName);

            return(SimpleAccess.ExecuteNonQuery(transaction, commandText, CommandType.StoredProcedure, oracleParameters));
        }
        /// <summary> Deletes the given dynamic object as OracleParameter names and values. </summary>
        ///
        /// <typeparam name="TEntity"> Type of the entity. </typeparam>
        /// <param name="paramObject"> The dynamic object as parameters. </param>
        ///
        /// <returns> . </returns>
        public virtual int Delete <TEntity>(object paramObject)
            where TEntity : class
        {
            //var name = typeof(TEntity).Name;
            var entityInfo  = RepositorySetting.GetEntity2Info(typeof(TEntity));
            var commandText = string.Format("{0}_Delete", entityInfo.DbObjectName);

            return(SimpleAccess.ExecuteNonQuery(commandText, CommandType.StoredProcedure, SimpleAccess.BuildOracleParameters(paramObject)));
        }
        /// <summary> Searches for all <typeparamref name="TEntity"/> that matches the conditions defined by the specified predicate, and returns the result as <see cref="IEnumerable{TEntity}"/>. </summary>
        ///
        /// <typeparam name="TEntity"> Type of the entity. </typeparam>
        /// <param name="transaction"> The transaction. </param>
        /// <param name="expression">The expression.</param>
        /// <param name="fieldToSkip"> (optional) the field to skip. </param>
        ///
        /// <returns> . </returns>
        public IEnumerable <TEntity> FindAll <TEntity>(OracleTransaction transaction, Expression <Func <TEntity, bool> > expression, string fieldToSkip = null)
            where TEntity : class, new()
        {
            var entityInfo = RepositorySetting.GetEntity2Info(typeof(TEntity));

            var commandText = string.Format("{0}_Find", entityInfo.DbObjectName);

            return(SimpleAccess.ExecuteEntities <TEntity>(transaction, commandText, CommandType.StoredProcedure
                                                          , fieldToSkip, parameters: new OracleParameter("@whereClause", DynamicQuery.GetStoredProcedureWhere(expression, entityInfo))));
        }
        /// <summary> Deletes the given ID. </summary>
        ///
        /// <typeparam name="TEntity"> Type of the entity. </typeparam>
        /// <param name="transaction">			 The SQL transaction. </param>
        /// <param name="id"> The identifier. </param>
        ///
        /// <returns> . </returns>
        public int Delete <TEntity>(OracleTransaction transaction, long id)
            where TEntity : class
        {
            //var name = typeof(TEntity).Name;
            var entityInfo = RepositorySetting.GetEntity2Info(typeof(TEntity));

            var commandText = string.Format("{0}_Delete", entityInfo.DbObjectName);
            var result      = SimpleAccess.ExecuteNonQuery(transaction, commandText, CommandType.StoredProcedure, new[] { OracleParametersExtensions.ToDataParam(id, (string)"Id") });

            return(result);
        }
        /// <summary> Updates the given TEntity. </summary>
        ///
        /// <typeparam name="TEntity"> Type of the entity. </typeparam>
        /// <param name="transaction">			 The SQL transaction. </param>
        /// <param name="entity"> Entity to insert </param>
        ///
        /// <returns> . </returns>
        public int Update <TEntity>(OracleTransaction transaction, TEntity entity)
            where TEntity : class
        {
            var entityInfo       = RepositorySetting.GetEntity2Info(typeof(TEntity));
            var entityParameters = entityInfo.GetUpdateParameters(entity);

            string commandText = string.Format("{0}_Update", entityInfo.DbObjectName);

            var result = SimpleAccess.ExecuteNonQuery(transaction, commandText, CommandType.StoredProcedure
                                                      , entityParameters.DataParametersDictionary.Values.ToArray());

            entityParameters.LoadOutParametersProperties(entity);

            return(result);
        }
        /// <summary> Inserts the given SQL parameters. </summary>
        ///
        /// <typeparam name="TEntity"> Type of the entity. </typeparam>
        /// <param name="transaction">			 The SQL transaction. </param>
        /// <param name="entities"> The <![CDATA[IEnumerable<TEntity>]]> to insert </param>
        ///
        /// <returns> The number of affected records</returns>
        public int InsertAll <TEntity>(OracleTransaction transaction, IEnumerable <TEntity> entities)
            where TEntity : class
        {
            int    result      = 0;
            var    entityInfo  = RepositorySetting.GetEntity2Info(typeof(TEntity));
            string commandText = string.Format("[dbo].{0}_Insert", entityInfo.DbObjectName);

            foreach (var entity in entities)
            {
                var entityParameters = entityInfo.GetInsertParameters(entity);

                result += SimpleAccess.ExecuteNonQuery(transaction, commandText, CommandType.StoredProcedure
                                                       , entityParameters.DataParametersDictionary.Values.ToArray());

                entityParameters.LoadOutParametersProperties(entity);
            }
            return(result);
        }