-
Notifications
You must be signed in to change notification settings - Fork 145
Bulk Copy with Objects
Jaxelr edited this page Dec 1, 2016
·
1 revision
You can also use the Insight mapping engine to send objects to SQL Server bulk copy. Just use the BulkCopy method:
List<Beer> beer = new List<Beer>();
beer.Add(new Beer() { Name = "Sly Fox IPA", Flavor = "yummy", OriginalGravity = 4.2m });
beer.Add(new Beer() { Name = "Hoppopotamus", Flavor = "hoppy", OriginalGravity = 3.0m });
Database.Connection().BulkCopy("Beer", beer);
The BulkCopy method will perform a BULK INSERT to write the data to the table. Insight will automatically map the objects to the table's schema.
You can also configure the data transfer options, such as the number of records in a batch:
Database.Connection().BulkCopy("Beer", beer,
configure: (InsightBulkCopy bulk) =>
{
bulk.BatchSize = 50;
// InsightBulkCopy wraps the provider-specific BulkCopy object
// you can get the provider object by:
var sqlBulk = (SqlBulkCopy)bulk.InnerBulkCopy;
});
- Home
- About
- Getting Started
- Connections
- Execute
- Getting Results
- Advanced Results & Mapping
- Insert/Update Considerations
- Data Types
- Write Even Less Code
- Performance & Speed
- Other Topics
- Supported Databases
- Working with the Code