Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JonathanMagnan/756aca8919d653d8da362937428f97bc to your computer and use it in GitHub Desktop.
Save JonathanMagnan/756aca8919d653d8da362937428f97bc to your computer and use it in GitHub Desktop.
using (var ctx = new CustomerContext())
{
List<Customer> customers = new List<Customer>();
foreach(var line in lines)
{
var customer = new Customer();
// ...code...
customers.Add(customer);
}
ctx.Customers.AddRange(customers);
ctx.SaveChanges();
}
using (var ctx = new CustomerContext())
{
// 1. CREATE a list
List<Customer> customers = new List<Customer>();
foreach(var line in lines)
{
var customer = new Customer();
// ...code...
// 2. ADD entity to the list
customers.Add(customer);
}
// 3. USE BulkInsert
ctx.BulkInsert();
// 4. Done!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment