/// <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); }
public async Task <IEnumerable <T> > AddRangeAsync(IEnumerable <T> entities) { _AspNetCoreWebApiContext.Entry(entities).State = EntityState.Added; await Entities.AddRangeAsync(entities); await _AspNetCoreWebApiContext.SaveChangesAsync(); return(entities); }
public virtual Task AddRange(params T[] entities) { if (entities == null) { throw new ArgumentNullException(nameof(entities)); } return(Entities.AddRangeAsync(entities)); }
public Task InsertAsync(IEnumerable <TEntity> entities) { if (!entities.Any()) { throw new ArgumentNullException("entities"); } return(Entities.AddRangeAsync(entities)); }
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)); }
public async Task InsertAsync(IEnumerable <TEntity> entities) { if (entities == null) { throw new ArgumentNullException(nameof(entities)); } await Entities.AddRangeAsync(entities); await _context.SaveChangesAsync(); }
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); } }
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)); }
/// <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); } }
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); } }
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); } }
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)); }
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); } }
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); }
public async Task AddAsync(IEnumerable <TEntity> items, CancellationToken cancellationToken) { Assert.NotNull(items, nameof(TEntity)); await Entities.AddRangeAsync(items, cancellationToken); }
/// <summary> /// 新增多条记录 /// </summary> /// <param name="entities">多个实体</param> /// <returns>Task</returns> public virtual Task InsertAsync(params TEntity[] entities) { return(Entities.AddRangeAsync(entities)); }
/// <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(); }
/// <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);
/// <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);
public virtual async Task AddRangeAsync(IEnumerable <TEntity> entities) => await Entities.AddRangeAsync(entities);