Hello!
is there a way to find out whether there are unsaved changes in my entity context, in the Entity Framework?
Thanks!
Hello!
is there a way to find out whether there are unsaved changes in my entity context, in the Entity Framework?
Thanks!
This might work (if by changes you mean added, removed and modified entities):
bool changesMade = (context.ObjectStateManager.GetObjectStateEntries(EntityState.Added).Count() +
context.ObjectStateManager.GetObjectStateEntries(EntityState.Deleted).Count() +
context.ObjectStateManager.GetObjectStateEntries(EntityState.Modified).Count()
) > 0;
Edit:
Improved code:
bool changesMade = context.
ObjectStateManager.
GetObjectStateEntries(EntityState.Added |
EntityState.Deleted |
EntityState.Modified
).Any();