EntityContext.SaveChange () takes longer on first call

I use BindingSource with Entity Framework and when I call

EntityContext.SaveChange();

it takes more time to execute, then the next time I add new objects to the binding source and then call SaveChanges (); Method

EDIT 2

More details:

When a upload form event

BindingSource.DataSource = EntityContext.Table;

Add New Button

BindingSource.AddNew();
Table m_object= (Table)BindingSource.Current;
m_object.ID = Guid.NewGuid();

Other object data is edited using controls bound to its properties.

And then the save button

BindingSource.EndEdit();
Stopwatch sw = new Stopwatch();
sw.Start();
EntityContext.SaveChanges();
sw.Stop();
Console.WriteLine(sw.Elapsed.ToString());

If I repeat adding and saving several times, I get the following output:

00: 00: 01.0788243

00: 00: 00.0316786

00: 00: 00.0292763

00: 00: 00.0298630

00: 00: 00,1127312

It is noteworthy that the first operation of adding and saving takes almost one second, and then the next time I add and save.

+3
3

, , AutoGrowing, . , , ,

EDIT:

, , , , "", , SQL? ( 0 , EF , )

+1

, , JIT ( ). #, MSIL (Microsoft Intermediate Language), , JIT , . , , , , .

AOT ( ), , , .

, # , , .

http://en.wikipedia.org/wiki/Just-in-time_compilation

0

Also, do not forget about the EF Change Tracker, which can cache data after the first operation. Based on MergeOption and the operation you perform, EF may choose not to even call the database. I would try a test with SQL Profiler to see the difference in the actual calls to the database. Also, check if subsequent calls use the same db connection.

0
source

All Articles