示例#1
0
        private async Task BulkInsertCoreAsync(IEnumerable <T> items, bool useAsync)
        {
            if (items != null)
            {
                using (var bulkInsert = _provider.CreateBulkInsert())
                {
                    bulkInsert.DestinationTableName = _tableInfo.Name;

                    const int defaultBatchSize = 100;
                    var       batchSize = items is ICollection <T> coll ? coll.Count : defaultBatchSize;

                    var idGenerator = CanGeneratePrimaryKeys()
                        ? _provider.CreateIdGenerator(_tableInfo.Name, batchSize)
                        : null;

                    using (var reader = new KormBulkInsertDataReader <T>(items, _commandGenerator, idGenerator, _tableInfo))
                    {
                        if (useAsync)
                        {
                            await bulkInsert.InsertAsync(reader);
                        }
                        else
                        {
                            bulkInsert.Insert(reader);
                        }
                    }
                }
            }
        }
示例#2
0
 /// <summary>
 /// Creates instance of <see cref="IBulkInsert"/>.
 /// </summary>
 /// <returns>Instance of <see cref="IBulkInsert"/>.</returns>
 public IBulkInsert CreateBulkInsert() => _queryProvider.CreateBulkInsert();