Performance Errors with Entity Framework

Technology at hand:

  • C # .NET 4.0
  • SQL Server 2014
  • Entity Framework 4.3.1
  • First code
  • ANTI Performance Profiler 7
  • SQL Server 2014 Profiler
  • Google search

Problem:
I am working on some programs. There is a definite problem that causes a serious slowdown. With an EF DataContextwith about 43 ADDEDentities, the method DataContext.SaveChanges()takes on the whole load of time.

Using SQL Profiler, I see that inserts occur with a duration (about) 0ms. This is as expected.

Using ANTS Profiler, I see DataContext.SaveChanges()(about) 1500 ms. Turning on it, 99.9%this time is spent inside SNINativeMethodWrapper.SNIReadSyncOverAsync.

Google, ( , , ). , 2 ( !).

SO, , :

, :

  • EF V6 + ( , )
  • CodeFirst
  • DataContext.SaveChanges()

, EF. ( ), .

  • Context.Configuration.ValidateOnSaveEnabled = false;
  • Context.Configuration.AutoDetectChangesEnabled = false;

:
- , ?

+4
1

:

, dbcontext ( -ambient DbContext), , / , (, , ), . , .

: "" Db ( , , ), EF , / , , DbContext (Connection, bool contextOwnsConnection = true) . , . , DELETE/UPDATE/INSERT ( , ) .

+1

Source: https://habr.com/ru/post/1618607/


All Articles