コード例 #1
0
 /// <summary>
 /// Insert entities
 /// </summary>
 /// <param name="entities">Entities</param>
 public virtual async Task InsertAsync(IEnumerable <T> entities)
 {
     if (entities == null)
     {
         throw new ArgumentNullException(nameof(entities));
     }
     await Entities.AddRangeAsync(entities);
 }
コード例 #2
0
        public async Task <IEnumerable <T> > AddRangeAsync(IEnumerable <T> entities)
        {
            _AspNetCoreWebApiContext.Entry(entities).State = EntityState.Added;
            await Entities.AddRangeAsync(entities);

            await _AspNetCoreWebApiContext.SaveChangesAsync();

            return(entities);
        }
コード例 #3
0
        public virtual Task AddRange(params T[] entities)
        {
            if (entities == null)
            {
                throw new ArgumentNullException(nameof(entities));
            }

            return(Entities.AddRangeAsync(entities));
        }
コード例 #4
0
        public Task InsertAsync(IEnumerable <TEntity> entities)
        {
            if (!entities.Any())
            {
                throw new ArgumentNullException("entities");
            }

            return(Entities.AddRangeAsync(entities));
        }
コード例 #5
0
        public virtual Task InsertAsync(IEnumerable <TEntity> entities, CancellationToken cancellationToken = default(CancellationToken))
        {
            DbSetCheck();

            if (entities == null)
            {
                throw new ArgumentNullException(nameof(entities));
            }

            return(Entities.AddRangeAsync(entities, cancellationToken));
        }
コード例 #6
0
        public async Task InsertAsync(IEnumerable <TEntity> entities)
        {
            if (entities == null)
            {
                throw new ArgumentNullException(nameof(entities));
            }

            await Entities.AddRangeAsync(entities);

            await _context.SaveChangesAsync();
        }
コード例 #7
0
ファイル: EfRepository.cs プロジェクト: Nurk21/DatesTestTask1
        public virtual async Task InsertManyAsync(IEnumerable <T> entities)
        {
            if (entities == null)
            {
                throw new ArgumentNullException(nameof(entities));
            }

            foreach (var entity in entities)
            {
                await Entities.AddRangeAsync(entity);
            }
        }
コード例 #8
0
        public virtual async Task <IEnumerable <TEntity> > AddAllAsync(IEnumerable <TEntity> entities, IUserContext userContext, CancellationToken ct = default)
        {
            return(await Task.Run(async() =>
            {
                foreach (var entity in entities)
                {
                    OnAdd(entity, userContext);
                }

                await Entities.AddRangeAsync(entities, ct).ConfigureAwait(false);

                return entities;
            }, ct));
        }
コード例 #9
0
        /// <summary>
        /// Insert Async
        /// </summary>
        /// <param name="entities">Entities</param>
        /// <returns>Result</returns>
        public virtual async Task InsertAsync(IEnumerable <T> entities)
        {
            try
            {
                if (entities == null)
                {
                    throw new ArgumentNullException(nameof(entities));
                }

                await Entities.AddRangeAsync(entities);
            }
            catch (Exception ex)
            {
                throw new Exception(GetFullErrorText(ex), ex);
            }
        }
コード例 #10
0
        public virtual async Task InsertAsync(IEnumerable <TEntity> entities)
        {
            if (entities == null)
            {
                throw new ArgumentNullException(nameof(entities));
            }

            try
            {
                await Entities.AddRangeAsync(entities);

                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException exception)
            {
                throw new Exception(await GetFullErrorTextAndRollbackEntityChangesAsync(exception), exception);
            }
        }
コード例 #11
0
        public virtual async Task <IEnumerable <T> > InsertAsync(IEnumerable <T> entities)
        {
            if (entities == null)
            {
                throw new ArgumentNullException(nameof(entities));
            }

            try
            {
                await Entities.AddRangeAsync(entities);

                await _context.SaveChangesAsync();

                return(entities);
            }
            catch (DbUpdateException exception)
            {
                //ensure that the detailed error text is saved in the Log
                throw new Exception(GetFullErrorTextAndRollbackEntityChanges(exception), exception);
            }
        }
コード例 #12
0
        public virtual async Task <IEnumerable <TEntity> > AddAllAsync(IEnumerable <TEntity> entities, IUserContext userContext, CancellationToken ct = default)
        {
            return(await Task.Run(async() =>
            {
                try
                {
                    foreach (var entity in entities)
                    {
                        OnAdd(entity, userContext);
                    }

                    await Entities.AddRangeAsync(entities, ct).ConfigureAwait(false);

                    return entities;
                }
                catch (Exception ex)
                {
                    throw new ServiceException("Erro", "Ocorreu um erro ao executar o serviço", ex);
                }
            }, ct));
        }
コード例 #13
0
        public async Task <int> InsertAsync(IEnumerable <TEntity> entities)
        {
            if (entities == null)
            {
                throw new ArgumentNullException(nameof(entities));
            }

            try
            {
                await Entities.AddRangeAsync(entities);

                return(await Context.SaveChangesAsync());
            }
            catch (DbUpdateException exception)
            {
                //TODO: add logging
                //ensure that the detailed error text is saved in the Log
                //throw new Exception(GetFullErrorTextAndRollbackEntityChanges(exception), exception);
                return(0);
            }
        }
コード例 #14
0
        public virtual async Task <int> BatchInsertAsync(TEntity[] entities, bool isSaveChange = true, CancellationToken cancellationToken = default)
        {
            if (entities == null)
            {
                throw new ArgumentException($"{typeof(TEntity)} is Null");
            }

            //自增ID操作会出现问题,暂时无法解决自增操作的方式,只能使用笨办法,通过多次连接数据库的方式执行
            //var changeRecord = 0;
            //foreach (var item in entities)
            //{
            //    var entry = Entities.Add(item);
            //    entry.State = EntityState.Added;
            //    changeRecord += _context.SaveChanges();
            //}

            await Entities.AddRangeAsync(entities);

            if (isSaveChange)
            {
                return(await SaveChangesAsync(cancellationToken));
            }
            return(0);
        }
コード例 #15
0
ファイル: Repository.cs プロジェクト: ali-safaei/Msp
 public async Task AddAsync(IEnumerable <TEntity> items, CancellationToken cancellationToken)
 {
     Assert.NotNull(items, nameof(TEntity));
     await Entities.AddRangeAsync(items, cancellationToken);
 }
コード例 #16
0
 /// <summary>
 /// 新增多条记录
 /// </summary>
 /// <param name="entities">多个实体</param>
 /// <returns>Task</returns>
 public virtual Task InsertAsync(params TEntity[] entities)
 {
     return(Entities.AddRangeAsync(entities));
 }
コード例 #17
0
        /// <summary>批量新增</summary>
        /// <typeparam name="T">泛型</typeparam>
        /// <param name="entities">新增集合</param>
        /// <returns></returns>
        public virtual async void AddAsync(IEnumerable <TEntity> entities)
        {
            await Entities.AddRangeAsync(entities);

            await _context.SaveChangesAsync();
        }
コード例 #18
0
ファイル: ResponsitryBase.cs プロジェクト: mylinx/Sky.Web
 /// <summary>
 /// Inserts a range of entities asynchronously.
 /// </summary>
 /// <param name="entities">The entities to insert.</param>
 /// <returns>A <see cref="Task" /> that represents the asynchronous insert operation.</returns>
 public virtual Task InsertAsync(params TEntity[] entities) => Entities.AddRangeAsync(entities);
コード例 #19
0
ファイル: ResponsitryBase.cs プロジェクト: mylinx/Sky.Web
 /// <summary>
 /// Inserts a range of entities asynchronously.
 /// </summary>
 /// <param name="entities">The entities to insert.</param>
 /// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe while waiting for the task to complete.</param>
 /// <returns>A <see cref="Task"/> that represents the asynchronous insert operation.</returns>
 public virtual Task InsertAsync(IEnumerable <TEntity> entities, CancellationToken cancellationToken = default(CancellationToken)) => Entities.AddRangeAsync(entities, cancellationToken);
コード例 #20
0
ファイル: Repository.cs プロジェクト: PFalkowski/StocksData
 public virtual async Task AddRangeAsync(IEnumerable <TEntity> entities)
 => await Entities.AddRangeAsync(entities);