Skip to content

dterziev/EnumerableDataReaderAdapter

Repository files navigation

EnumerableDataReaderAdapter

An adapter that allows converting an IEnumerable to IDataReader that can be used as a data source for SqlBulkCopy.

Usage

var data = Enumerable.Range(1, 10000).Select(x => new { Id = x, Name = $"name-{x}" });

using var reader = data.ToDataReader(map => map.Add(x => x.Id).Add(x => x.Name));

using var sqlBulkCopy = new SqlBulkCopy(connectionString);
sqlBulkCopy.BatchSize = 10000;
sqlBulkCopy.ColumnMappings.Add("Id", "Id");
sqlBulkCopy.ColumnMappings.Add("Name", "Name");
sqlBulkCopy.DestinationTableName = "dbo.TableName";
sqlBulkCopy.EnableStreaming = true;
await sqlBulkCopy.WriteToServerAsync(reader);

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages