How can I check for pending Entity Framework changes?

.net c# entity-framework

Question

I'm using the ADO.NET Entity Framework to build an application.

I can go through my code line-by-line while debugging and see every query done in SQL Server Profiler, but I still can't figure out where all those SQL commands are coming from!

sometimes when I carry outSaveChanges() the Entity Framework makes strange, unexpected INSERTS. Sometimes they ruin the program. I am unable to determine what I am doing to trigger them.

How can I keep track of the modifications that are queued up and waiting for aSaveChanges() call?

1
45
7/1/2017 7:11:50 PM

Popular Answer

Beginning with Entity Framework 5.0DbContext has an all-pending changes ChangeTracker property. comparable to theObjectStateManager Entities may be found in the following states:

myDbContext.ChangeTracker.Entries().Where(e => e.State == EntityState.Added);
myDbContext.ChangeTracker.Entries().Where(e => e.State == EntityState.Deleted);
myDbContext.ChangeTracker.Entries().Where(e => e.State == EntityState.Modified);
52
8/11/2014 10:07:49 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow