With Distinction

I wanted to fire an event when a particular entity type is updated in the store. For example, when any value in a table is modified. How to do it? The context's SavingChanges event is the entry but how to determine which type of data is getting updated? Enter the ObjectStateManager. It'll return collections based on object states, modified, new, deleted, etc. All we need to do is examine the modified objects and fire events based on their types, right? Not so fast - the state manager returns ALL the objects being saved, so there could be many, many entities of any given type and simply firing events when we see a prticular type would result in many unnecessary events. Enter a Distinct Linq query:
var entSets = ( from obj in ObjectStateManager.GetObjectStateEntries( EntityState.Modified )
                        select obj.EntitySet ).Distinct();
This query will gather the EntitySet references from all the objects being saved. Notice the oarens around the query and the Distinct() tacked on the end - this will filter the set to eliminate duplicates - so when we iterate the set, we get exactly one instance of each affected EntitySet. Then we match the EntitySet to an event and we're done. abbreviated...
            foreach ( var set in entSets.Distinct() ) {
                if ( set.Name == "SysVars" )
                    log.Info( "SysVars Modified" );
            }