Is there a way to find out whether there are unsaved changes in my entity context, in the Entity Framework?
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();