Created
September 29, 2017 14:13
-
-
Save aaronolds/9591c96a9a429ffc3258b231cad832d6 to your computer and use it in GitHub Desktop.
Detach all entities in a DbContext before loading it again with data. The only issue I have with this is, that the detached entities are still in memory.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
public void DetatchAllEntities() | |
{ | |
ChangeTracker.Entries().Where(dbEntityEntry => dbEntityEntry.Entity != null).ToList().ForEach(e => e.State = System.Data.Entity.EntityState.Detached); | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment