Example #1
0
        /// <inheritdoc />
        public virtual async Task <bool> UpdateAsync(Expression <Func <TEntity, bool> > predicate, TEntity instance, IDbTransaction transaction)
        {
            var sqlQuery = SqlGenerator.GetUpdate(predicate, instance);
            var updated  = (await TransientDapperExtentions.ExecuteWithRetryAsync(() => Connection.ExecuteAsync(sqlQuery.GetSql(), instance, transaction))) > 0;

            return(updated);
        }
Example #2
0
        /// <inheritdoc />
        public async Task <bool> BulkUpdateAsync(IEnumerable <TEntity> instances, IDbTransaction transaction)
        {
            var queryResult = SqlGenerator.GetBulkUpdate(instances);
            var result      = (await TransientDapperExtentions.ExecuteWithRetryAsync(() => Connection.ExecuteAsync(queryResult.GetSql(), queryResult.Param, transaction))) > 0;

            return(result);
        }
        /// <inheritdoc />
        public virtual async Task <bool> DeleteAsync(Expression <Func <TEntity, bool> > predicate, IDbTransaction transaction = null)
        {
            var queryResult = SqlGenerator.GetDelete(predicate);
            var deleted     = (await TransientDapperExtentions.ExecuteWithRetryAsync(() => Connection.ExecuteAsync(queryResult.GetSql(), queryResult.Param, transaction))) > 0;

            return(deleted);
        }
Example #4
0
        /// <inheritdoc />
        public virtual async Task <int> BulkInsertAsync(IEnumerable <TEntity> instances, IDbTransaction transaction = null)
        {
            var queryResult = SqlGenerator.GetBulkInsert(instances);
            var count       = await TransientDapperExtentions.ExecuteWithRetryAsync(() => Connection.ExecuteAsync(queryResult.GetSql(), queryResult.Param, transaction));

            return(count);
        }
        /// <inheritdoc />
        public virtual async Task <bool> InsertAsync(TEntity instance, IDbTransaction transaction)
        {
            var queryResult = SqlGenerator.GetInsert(instance);

            if (SqlGenerator.IsIdentity)
            {
                var newId = (await Connection.QueryAsync <long>(queryResult.GetSql(), queryResult.Param, transaction)).FirstOrDefault();
                return(SetValue(newId, instance));
            }
            return(await TransientDapperExtentions.ExecuteWithRetryAsync(() => Connection.ExecuteAsync(queryResult.GetSql(), instance, transaction)) > 0);
        }
        /// <inheritdoc />
        public virtual async Task <bool> UpSertAsync(TEntity instance, IDbTransaction transaction = null)
        {
            var  sqlQuery = SqlGenerator.GetUpSert(instance);
            bool modified;

            if (SqlGenerator.IsIdentity)
            {
                var newId = (await TransientDapperExtentions.QueryWithRetryAsync(() => Connection.QueryAsync <long>(sqlQuery.GetSql(), sqlQuery.Param, transaction))).FirstOrDefault();
                modified = newId > 0;

                if (modified)
                {
                    var newParsedId = Convert.ChangeType(newId, SqlGenerator.IdentitySqlProperty.PropertyInfo.PropertyType);
                    SqlGenerator.IdentitySqlProperty.PropertyInfo.SetValue(instance, newParsedId);
                }
            }
            else
            {
                modified = (await TransientDapperExtentions.ExecuteWithRetryAsync(() => Connection.ExecuteAsync(sqlQuery.GetSql(), instance, transaction))) > 0;
            }

            return(modified);
        }