/// <inheritdoc /> public async Task InsertAsync <TItem>( IEnumerable <TItem> items, Action <TransactSqlInsertBase <TEntity> > insertAction, CancellationToken cancellationToken) { if (items == null) { throw new ArgumentNullException(nameof(items)); } TransactSqlInsertBase <TEntity> insertCommand; if (items == null) { throw new ArgumentNullException(nameof(items)); } if (typeof(TItem).GetCustomAttribute <TableTypeAttribute>() == null) { insertCommand = new JsonInsert <TEntity>(this.RepositoryProvider.DatabaseContext); } else { insertCommand = new TableValuedInsert <TEntity>(this.RepositoryProvider.DatabaseContext); } insertAction?.Invoke(insertCommand); await insertCommand.ExecuteAsync(items, cancellationToken).ConfigureAwait(false); }
/// <inheritdoc/> public async IAsyncEnumerable <TItem> InsertForResultsAsync <TItem>( IEnumerable <TItem> items, Action <TransactSqlInsertBase <TEntity> > insertAction, [EnumeratorCancellation] CancellationToken cancellationToken) { if (items == null) { throw new ArgumentNullException(nameof(items)); } TransactSqlInsertBase <TEntity> insertCommand; if (items == null) { throw new ArgumentNullException(nameof(items)); } if (typeof(TItem).GetCustomAttribute <TableTypeAttribute>() == null) { insertCommand = new JsonInsert <TEntity>(this.RepositoryProvider.DatabaseContext); } else { insertCommand = new TableValuedInsert <TEntity>(this.RepositoryProvider.DatabaseContext); } insertAction?.Invoke(insertCommand); await foreach (var item in insertCommand.ExecuteForResultsAsync(items, cancellationToken).ConfigureAwait(false)) { yield return(this.EntityMapper.Map <TItem>(item)); } }
/// <inheritdoc/> public IEnumerable <TItem> InsertForResults <TItem>( IEnumerable <TItem> items, Action <TransactSqlInsertBase <TEntity> > insertAction) { if (items == null) { throw new ArgumentNullException(nameof(items)); } TransactSqlInsertBase <TEntity> insertCommand; if (items == null) { throw new ArgumentNullException(nameof(items)); } if (typeof(TItem).GetCustomAttribute <TableTypeAttribute>() == null) { insertCommand = new JsonInsert <TEntity>(this.RepositoryProvider.DatabaseContext); } else { insertCommand = new TableValuedInsert <TEntity>(this.RepositoryProvider.DatabaseContext); } insertAction?.Invoke(insertCommand); var entities = insertCommand.ExecuteForResults(items); return(this.EntityMapper.Map <List <TItem> >(entities)); }
/// <inheritdoc/> public void Insert <TItem>(IEnumerable <TItem> items, Action <TransactSqlInsertBase <TEntity> > insertAction) { TransactSqlInsertBase <TEntity> insertCommand; if (items == null) { throw new ArgumentNullException(nameof(items)); } if (typeof(TItem).GetCustomAttribute <TableTypeAttribute>() == null) { insertCommand = new JsonInsert <TEntity>(this.RepositoryProvider.DatabaseContext); } else { insertCommand = new TableValuedInsert <TEntity>(this.RepositoryProvider.DatabaseContext); } insertAction?.Invoke(insertCommand); insertCommand.Execute(items); }