CSharp · Console
// @nuget: EntityFramework
using System;
using System.Data.Entity;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
public class Program
{
public static void Main()
{
List<Customer> list = Data();
// SaveChanges
using (var context = new CustomerContext())
{
// list contains 2000 records
context.Customers.AddRange(list);
context.SaveChanges();
FiddleHelper.WriteTable(context.Customers.Take(5).ToList());
}
}
public static List<Customer> Data()
{
List<Customer> list = new List<Customer>();
for(int i = 0; i < 2000; i++)
{
list.Add(new Customer() { Name ="Customer_" + i});
}
return list;
}
public class CustomerContext : DbContext
{
public CustomerContext() : base(FiddleHelper.GetConnectionStringSqlServer())
{
}
public DbSet<Customer> Customers { get; set; }
}
public class Customer
{
public int CustomerID { get; set; }
public string Name { get; set; }
}
}