Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        /// <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));
            }
        }
Ejemplo n.º 3
0
        /// <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));
        }
Ejemplo n.º 4
0
        /// <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);
        }