public static Task BulkInsertAsync <T>([NotNull] this DbContext ctx, [NotNull] IEnumerable <T> entities, [NotNull] Expression <Func <T, object> > propertiesToInsert, CancellationToken cancellationToken = default) where T : class { var options = new SqlBulkInsertOptions { EntityMembersProvider = EntityMembersProvider.From(propertiesToInsert) }; return(BulkInsertAsync(ctx, entities, options, cancellationToken)); }
public static async Task BulkInsertAsync <T>([NotNull] this DbContext ctx, [NotNull] IEnumerable <T> entities, [CanBeNull] SqlBulkInsertOptions options = null, CancellationToken cancellationToken = default) where T : class { if (ctx == null) { throw new ArgumentNullException(nameof(ctx)); } if (entities == null) { throw new ArgumentNullException(nameof(entities)); } options = options ?? new SqlBulkInsertOptions(); var entityType = ctx.Model.GetEntityType(typeof(T)); await ctx.GetService <ISqlServerBulkOperationExecutor>().BulkInsertAsync(ctx, entityType, entities, options, cancellationToken).ConfigureAwait(false); }