The three typical levels of my current project are data, business, and presentation. For all of my data access requirements, I'd prefer to utilize data entities. The program will need to replicate all of the data from a flat file into a database as part of its functionality. Because the file isn't that large, I can utilize SqlBulkCopy. I've come across a number of articles on how to use the SqlBulkCopy class in.NET. To transfer data back and forth, DataTables are used in every article.
Is it possible to combine SqlBulkCopy with data entities, or would I have to use DataTables instead?
In addition to @DaveHogan's response,
There are now new libraries that enable Bulk Insert for Entity Framework utilizing data entities instead of DataTable (behind the hood, SqlBulkCopy).
I am the project's owner, according to Disclaimer.
Although this library is not free, it makes it simple to:
In the background, SqlBulkCopy is used. Instead of having to code a unique solution for each Bulk Insert, using the extension technique is more simpler and quicker.
// Easy to use context.BulkSaveChanges(); // Easy to customize context.BulkSaveChanges(bulk => bulk.BatchSize = 100);
I'm sorry you're not doing well.
Make sure you are not accounting for time lost due to typical errors like failing to JIT Compile or using Add rather than AddRange, which have an influence on test performance but are unrelated to our library.
When removing all frequent performance benchmark errors, most users claim to have seen a performance gain of 25–50 times.
The Entities must be transformed into an IDataReader or DataTable.
There is a little helper class available to aid with: http://archive.msdn.microsoft.com/LinqEntityDataReader/Release/ProjectReleases.aspx?ReleaseId=389
EDIT: The link to the alternative version on MSDN is here: https://github.com/matthewschrager/Repository/blob/master/Repository.EntityFramework/EntityDataReader.cs
Then, you may use SqlBulkCopy as follows:
var sbCopy= new SqlBulkCopy(connectionString); sbCopy.DestinationTableName = "TableName"; sbCopy.WriteToServer(entitiesList.AsDataReader());