esc_toe_account
asked on
Determining if ObjectStateManager has dirty records
I would like a sanity check.
Here is a static method I wrote to determine if the .Net Framework Entity's ObjectStateManager has any dirty records. (This code would be used to determine the state of the Save button, namely, count>0 means enabled else disabled.)
Is there no easier way to do this? Does ObjectStateManager not have any kind of a property to flag whether its contents are dirty?
Here is a static method I wrote to determine if the .Net Framework Entity's ObjectStateManager has any dirty records. (This code would be used to determine the state of the Save button, namely, count>0 means enabled else disabled.)
Is there no easier way to do this? Does ObjectStateManager not have any kind of a property to flag whether its contents are dirty?
static public int ChangedCount(this ObjectStateManager manager)
{
int changedCount = 0;
try
{
changedCount += manager.GetObjectStateEntries(EntityState.Added).Count<ObjectStateEntry>();
}
catch {}
try
{
changedCount += manager.GetObjectStateEntries(EntityState.Deleted).Count<ObjectStateEntry>();
}
catch { }
try
{
changedCount += manager.GetObjectStateEntries(EntityState.Modified).Count<ObjectStateEntry>();
}
catch { }
return changedCount;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I guess one line of code is not bad but I would still like to hear whether there is a property in the manager that simply says dirty or not.