EDIT: the issue below has been fixed in the Entity Framework 6.
Running the code below takes a disappointing 2 minutes and 10 seconds. Running it a second time takes 6.5 minutes. This question is related to this one
Private Sub RunTest()
Dim sw As New Stopwatch
sw.Restart()
Using db As New TestDB
db.Configuration.AutoDetectChangesEnabled = False
For n = 1 To 100
For m = 1 To 100
db.Tops.Add(New Top)
Next
Next
db.SaveChanges()
End Using
MsgBox(sw.Elapsed.ToString)
End Sub
The Entity:
Public Class Top
Public Sub New()
MyBase.New()
One = "arerjlwkerjglwejrglwergoiwerhgiowehrowerlwelfvbwlervbowerghpiweurhgpiwuerviiervljwebbrlvjnepvjnweprvupiweurv"
Two = "w;lrjgwwergkjwervgjwelrgjhwelghlwekglwergiuwehrgwjergjwervgjwerjgnwekrngpwergjpowergllwejrnglkwerngpoierhpiiuewrpjwenrwenrv;lwenrvkjernpgpsrvpi"
End Sub
'ID'
Public Property ID As Integer
'NATIVE PROPERTIES'
Public Overridable Property One As String
Public Overridable Property Two As String
'NAVIGATION PROPERTIES'
End Class
Moving the Using block inside the second level interation and calling SaveChanges there makes it only worse.
TestDB just inherits DBContext without any further configuration.When I disable database generation of the Top.ID property and supply the ID myself the performance improves a thirty fold.This problem makes using Database generated ID's in SQL Server Compact impossible. Is there a solution other than using client side generated IDs?