コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="context"></param>
        /// <param name="entities"></param>
        /// <param name="options"></param>
        public static void BulkInsert <T>(this DbContext context, IEnumerable <T> entities, BulkInsertOptions options)
        {
            var bulkInsert = ProviderFactory.Get(context);

            bulkInsert.Options = options;
            bulkInsert.Run(entities);
        }
コード例 #2
0
        public static async Task BulkInsertBuffered <T>(this DbContext context, IEnumerable <T> entities, BulkInsertOptions options)
        {
            var bulkInsert = ProviderFactory.Get(context);

            bulkInsert.Options = options;
            var mutualExclusionLock = new object();

            var t1 = Task.Run(async() => await BulkInsertBufferedBody <T>(bulkInsert, entities, options, mutualExclusionLock));
            var t2 = Task.Run(async() => await BulkInsertBufferedBody <T>(bulkInsert, entities, options, mutualExclusionLock));

            await Task.WhenAll(t1, t2);
        }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="context"></param>
        /// <param name="entities"></param>
        /// <param name="options"></param>
        public static Task BulkInsertAsync <T>(this DbContext context, IEnumerable <T> entities, BulkInsertOptions options)
        {
            var bulkInsert = ProviderFactory.Get(context);

            bulkInsert.Options = options;
            return(bulkInsert.RunAsync(entities));
        }
コード例 #4
0
        public static async Task BulkInsertBufferedBody <T>(IEfBulkInsertProvider bulkInsert, IEnumerable <T> entities, BulkInsertOptions options, object mutualExclusionLock)
        {
            while (true)
            {
                var buffer = new List <T>();
                lock (mutualExclusionLock)
                {
                    foreach (var item in entities)
                    {
                        buffer.Add(item);
                        if (buffer.Count == options.BatchSize)
                        {
                            break;
                        }
                    }
                }

                if (!buffer.Any())
                {
                    return;
                }
                await BulkInsertAsync(bulkInsert.Context, buffer, options);
            }
        }