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()
{
using (var context = new EntityContext())
{
context.Configuration.AutoDetectChangesEnabled = false;
List<Customer> list = new List<Customer>();
for(int i = 0; i < 2000; i++)
{
var customer = new Customer();
customer.Name ="Customer_" + i;
list.Add(customer);
}
context.Customers.AddRange(list);
context.ChangeTracker.DetectChanges();
context.SaveChanges();
FiddleHelper.WriteTable(context.Customers.Take(5).ToList());
}
}
public class EntityContext : DbContext
{
public EntityContext() : base(FiddleHelper.GetConnectionStringSqlServer())
{
}
public DbSet<Customer> Customers { get; set; }
}
public class Customer
{
public int CustomerID { get; set; }
public string Name { get; set; }
}
}