Exemple #1
0
        /// <inheritdoc/>
        /// <remarks>
        /// In SQL Server, MERGE operations are not guaranteed to be atomic.
        /// </remarks>
        public async IAsyncEnumerable <TItem> MergeForResultsAsync <TItem>(
            IEnumerable <TItem> items,
            Action <TransactSqlMergeBase <TEntity> > mergeAction,
            [EnumeratorCancellation] CancellationToken cancellationToken)
        {
            if (items == null)
            {
                throw new ArgumentNullException(nameof(items));
            }

            TransactSqlMergeBase <TEntity> mergeCommand;

            if (typeof(TItem).GetCustomAttribute <TableTypeAttribute>() == null)
            {
                mergeCommand = new JsonMerge <TEntity>(this.RepositoryProvider.DatabaseContext);
            }
            else
            {
                mergeCommand = new TableValuedMerge <TEntity>(this.RepositoryProvider.DatabaseContext);
            }

            mergeAction?.Invoke(mergeCommand);

            await foreach (var item in mergeCommand.ExecuteForResultsAsync(items, cancellationToken).ConfigureAwait(false))
            {
                yield return(this.EntityMapper.Map <TItem>(item));
            }
        }
Exemple #2
0
        /// <inheritdoc/>
        /// <remarks>
        /// In SQL Server, MERGE operations are not guaranteed to be atomic.
        /// </remarks>
        public IEnumerable <TItem> MergeForResults <TItem>(
            IEnumerable <TItem> items,
            Action <TransactSqlMergeBase <TEntity> > mergeAction)
        {
            if (items == null)
            {
                throw new ArgumentNullException(nameof(items));
            }

            TransactSqlMergeBase <TEntity> mergeCommand;

            if (typeof(TItem).GetCustomAttribute <TableTypeAttribute>() == null)
            {
                mergeCommand = new JsonMerge <TEntity>(this.RepositoryProvider.DatabaseContext);
            }
            else
            {
                mergeCommand = new TableValuedMerge <TEntity>(this.RepositoryProvider.DatabaseContext);
            }

            mergeAction?.Invoke(mergeCommand);
            var entities = mergeCommand.ExecuteForResults(items);

            return(this.EntityMapper.Map <List <TItem> >(entities));
        }
Exemple #3
0
        /// <inheritdoc/>
        /// <remarks>
        /// In SQL Server, MERGE operations are not guaranteed to be atomic.
        /// </remarks>
        public void Merge <TItem>(IEnumerable <TItem> items, Action <TransactSqlMergeBase <TEntity> > mergeAction)
        {
            if (items == null)
            {
                throw new ArgumentNullException(nameof(items));
            }

            TransactSqlMergeBase <TEntity> mergeCommand;

            if (typeof(TItem).GetCustomAttribute <TableTypeAttribute>() == null)
            {
                mergeCommand = new JsonMerge <TEntity>(this.RepositoryProvider.DatabaseContext);
            }
            else
            {
                mergeCommand = new TableValuedMerge <TEntity>(this.RepositoryProvider.DatabaseContext);
            }

            mergeAction?.Invoke(mergeCommand);
            mergeCommand.Execute(items);
        }
Exemple #4
0
        /// <inheritdoc/>
        /// <remarks>
        /// In SQL Server, MERGE operations are not guaranteed to be atomic.
        /// </remarks>
        public async Task MergeAsync <TItem>(
            IEnumerable <TItem> items,
            Action <TransactSqlMergeBase <TEntity> > mergeAction,
            CancellationToken cancellationToken)
        {
            if (items == null)
            {
                throw new ArgumentNullException(nameof(items));
            }

            TransactSqlMergeBase <TEntity> mergeCommand;

            if (typeof(TItem).GetCustomAttribute <TableTypeAttribute>() == null)
            {
                mergeCommand = new JsonMerge <TEntity>(this.RepositoryProvider.DatabaseContext);
            }
            else
            {
                mergeCommand = new TableValuedMerge <TEntity>(this.RepositoryProvider.DatabaseContext);
            }

            mergeAction?.Invoke(mergeCommand);
            await mergeCommand.ExecuteAsync(items, cancellationToken).ConfigureAwait(false);
        }