Imports System.Collections.Generic
Imports System.Diagnostics
Imports System.Data.Entity
Dim customers = GenerateCustomers(1000)
Dim clockSaveChanges = New Stopwatch()
Dim clockBulkSaveChanges = New Stopwatch()
Dim clockBulkInsert = New Stopwatch()
Using context = New EntityContext()
context.Customers.AddRange(customers)
clockSaveChanges.[Stop]()
BenchmarkResults.Add(new BenchmarkResult() { Action = "
SaveChanges(Entity, Framework) And quot
Entities = customers.Count
context.Customers.AddRange(customers);
clockBulkSaveChanges.Start();
context.BulkSaveChanges(); // performance can be improved with options
clockBulkSaveChanges.Stop();
BenchmarkResults.Add(new BenchmarkResult() { Action = "BulkSaveChanges", Entities = customers.Count, Performance = clockBulkSaveChanges.ElapsedMilliseconds + " ms" })
using (var context = new EntityContext())
context.BulkInsert(customers); // performance can be improved with options
BenchmarkResults.Add(new BenchmarkResult() { Action = "BulkInsert", Entities = customers.Count, Performance = clockBulkInsert.ElapsedMilliseconds + " ms" })
FiddleHelper.WriteTable("
public static void JustInTime_Compile()
var customers = GenerateCustomers(20);
using (var context = new EntityContext())
context.Customers.AddRange(customers);
context.Customers.RemoveRange(customers);
using (var context = new EntityContext())
context.Customers.AddRange(customers);
context.BulkSaveChanges();
context.Customers.RemoveRange(customers);
context.BulkSaveChanges();
using (var context = new EntityContext())
context.BulkInsert(customers);
context.BulkDelete(customers);
var list = new List<...' at character 2733
var list = new List<Customer>();
for(int i = 0; i < count; i++)
list.Add(new Customer() { Name = "Customer_" + i, Description = "Description_" + i, IsActive = i % 2 == 0 });
Public Class EntityContext
MyBase.New(FiddleHelper.GetConnectionStringSqlServer())
Public Property CustomerID As Integer
Public Property Name As String
Public Property Description As String
Public Property IsActive As Boolean
Public Class BenchmarkResult
Public Property Action As String
Public Property Entities As Integer
Public Property Performance As String