Ejemplo n.º 1
0
        /// <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>(MySqlTransaction transaction, long id)
            where TEntity : class
        {
            //var name = typeof(TEntity).Name;
            var entityInfo = RepositorySetting.GetEntityInfo(typeof(TEntity));

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

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary> Gets. </summary>
        ///
        /// <typeparam name="TEntity"> Type of the entity. </typeparam>
        /// <param name="id">		   The identifier. </param>
        /// <param name="transaction"> (optional) the transaction. </param>
        /// <param name="fieldToSkip"> (optional) the field to skip. </param>
        ///
        /// <returns> . </returns>
        public TEntity Get <TEntity>(MySqlTransaction transaction, long id, string fieldToSkip = null)
            where TEntity : class, new()
        {
            var entityInfo = RepositorySetting.GetEntityInfo(typeof(TEntity));

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

            return(SimpleAccess.ExecuteEntity <TEntity>(transaction, commandText, CommandType.StoredProcedure, fieldToSkip, null,
                                                        new MySqlParameter("@id", id)));

            // return Get<TEntity>(new MySqlParameter("@id", id), transaction, fieldToSkip);
        }
Ejemplo n.º 3
0
        /// <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>
        /// <param name="transaction"> The SQL transaction. </param>
        ///
        /// <returns> Number of rows affected (integer) </returns>
        public int DeleteAll <TEntity>(MySqlTransaction transaction, IEnumerable <long> ids)
            where TEntity : class
        {
            int result = 0;

            var entityInfo  = RepositorySetting.GetEntityInfo(typeof(TEntity));
            var commandText = string.Format("{0}_Delete", entityInfo.DbObjectName);

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

            return(result);
        }
Ejemplo n.º 4
0
        /// <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>(MySqlTransaction transaction, TEntity entity)
            where TEntity : class
        {
            var entityInfo       = RepositorySetting.GetEntityInfo(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);
        }
Ejemplo n.º 5
0
        /// <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>(MySqlTransaction transaction, IEnumerable <TEntity> entities)
            where TEntity : class
        {
            int    result      = 0;
            var    entityInfo  = RepositorySetting.GetEntityInfo(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);
        }