Example #1
0
 /// <summary>
 /// Perform an <c>update versioned</c> on all entities selected by the specified query. The update operation is performed in the database without
 /// reading the entities out of it.
 /// </summary>
 /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
 /// <param name="source">The query matching the entities to update.</param>
 /// <param name="expression">The update setters expressed as a member initialization of updated entities, e.g.
 /// <c>x => new Dog { Name = x.Name, Age = x.Age + 5 }</c>. Unset members are ignored and left untouched.</param>
 /// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
 /// <returns>The number of updated entities.</returns>
 public static Task <int> UpdateVersionedAsync <TSource>(this IQueryable <TSource> source, Expression <Func <TSource, TSource> > expression, CancellationToken cancellationToken = default(CancellationToken))
 {
     if (cancellationToken.IsCancellationRequested)
     {
         return(Task.FromCanceled <int>(cancellationToken));
     }
     try {
         return(ExecuteUpdateAsync(source, DmlExpressionRewriter.PrepareExpression(source.Expression, expression), true, cancellationToken));
     } catch (Exception ex) {
         return(Task.FromException <int>(ex));
     }
 }
Example #2
0
 /// <summary>
 /// Insert all entities selected by the specified query. The insert operation is performed in the database without reading the entities out of it.
 /// </summary>
 /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
 /// <typeparam name="TTarget">The type of the entities to insert.</typeparam>
 /// <param name="source">The query matching entities source of the data to insert.</param>
 /// <param name="expression">The expression projecting a source entity to the entity to insert.</param>
 /// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
 /// <returns>The number of inserted entities.</returns>
 public static Task <int> InsertIntoAsync <TSource, TTarget>(this IQueryable <TSource> source, Expression <Func <TSource, TTarget> > expression, CancellationToken cancellationToken = default(CancellationToken))
 {
     if (cancellationToken.IsCancellationRequested)
     {
         return(Task.FromCanceled <int>(cancellationToken));
     }
     try {
         return(ExecuteInsertAsync <TSource, TTarget>(source, DmlExpressionRewriter.PrepareExpression(source.Expression, expression), cancellationToken));
     } catch (Exception ex) {
         return(Task.FromException <int>(ex));
     }
 }
Example #3
0
 /// <summary>
 /// Perform an <c>update versioned</c> on the entities. The update operation is performed in the database without reading the entities out of it.
 /// </summary>
 /// <returns>The number of updated entities.</returns>
 public int UpdateVersioned() => _source.ExecuteUpdate(DmlExpressionRewriter.PrepareExpression <TSource>(_source.Expression, _assignments.List), true);