The technologies at hand:
- C# .NET 4.0
- SQL Server 2014
- Entity Framework 4.3.1
- Code First
- ANTS Performance Profiler 7
- SQL Server 2014 Profiler 2
- Google Search
The problem:
I'm doing performance work on some software. There's a particular issue that causes a serious slow down. With an EF DataContext
with around 43 ADDED
entities, the DataContext.SaveChanges()
method takes eats up a whole load of time.
Using SQL Profiler I can see the inserts taking place with a duration of (about) 0ms
. This is as expected.
Using ANTS Profiler I can see DataContext.SaveChanges()
taking (about) 1,500ms. Drilling down into this, 99.9%
of this time is spent inside SNINativeMethodWrapper.SNIReadSyncOverAsync
.
Using Google, there are very few useful results (well none, hence this question). For the first time in a long time, I found myself looking into page 2 and beyond of the Google results (uncharted waters!).
There are a couple of questions on SO that reference this method but from different contexts:
- snireadsyncoverasync-performance-issue
- snireadsyncoverasync-and-waitforsingleobject-blocking-ef-performance
I'm looking for a solution that does not require any of:
- Upgrade EF to V6+ (or any other version for that matter)
- Move away from CodeFirst
- Not use DataContext.SaveChanges()
- Re-architect the software
I should add that I have disabled the following EF settings. This has a positive effect overall (as expected) but has no effect on the problem domain.
Context.Configuration.ValidateOnSaveEnabled = false;
Context.Configuration.AutoDetectChangesEnabled = false;
The Question:
Can anyone suggest a code change that can resolve or avoid this issue?