Project Description
Entity Framework ETL is used to batch commands using an existing DbContext. This is useful when moving data between production and development.

Changes To SaveBatchedChanges Method
SaveBatchedChanges now supports complex batch insert operations. It will perform batch inserts on a complex entity graph and will update related foreign keys automatically in the database (currently database only).

SaveBatchedChanges Example
//currently do not support stored procedures.
//Your primary keys must be named Id
//Your foreign key name must end with Id
using (var context = new YourContext())
{
IEnumerable<World> worlds = new List<World>();
context.Worlds.AddRange(worlds);
context.SaveBatchedChanges();
}

SaveBatchedChanges Performance
Commands Save Changes Save Batched Changes
1000 3.5 1.3
5000 16.7 4.3
10000 33.8 5.8

Example Usage
ETL = new EntityFrameworkETL.ETL(() => new DataContext("name=source"), () => new DataContext("name=target"));
ETL.DeleteAll<Person>();
ETL.BatchInserts<Person>(100, true, x => x.Include("Jobs").Where(y=> y.Age > 65 && y.IsRetired));

Batch Insert Notes
The batch inserts above use Entity Framework 6 interceptors to cache the sql commands locally and then send them in batches. Parameterized sql is used and the number of commands sent in one batch will be automatically corrected for Sql Server's max sql parameter amount for a sql command.

Useful Tips
Entity Framework ETL supports inserting primary key columns even if your target entities have autogenerated primary keys. Add the ConditionallyInsertIdentity attribute to your entity that has a autogenerated primary key. Set up a compile flag for Entity Framework ETL. Create a conditional compilation symbol for IdentityInsert. Turn off code first database change warning with the following code: Database.SetInitializer<DataContextHere>(null);

Nuget
PM> Install-Package EntityFrameworkETL

Last edited May 17, 2014 at 3:25 PM by ChrisPerry, version 20