Storing Entity Changes
What happens if the records in the database that are represented by the entity classes have been changed after reading the record? The answer depends on the ConcurrencyMode property that is set with the    
model. With every property of an entity object, you can configure the ConcurrencyMode to Fixed or None. The value Fixed means that the property is validated at write time to determine if the value was     
not changed in the meantime. None — which is the default — ignores any change. If some properties are configured to the Fixed mode, and data changed between reading and writing the entity objects, an     
OptimisticConcurrencyException occurs.
You can deal with this exception by invoking the Refresh() method to read the actual information from the database into the object context. This method accepts two refresh modes configured by a RefreshMode enumeration value: ClientWins or StoreWins. StoreWins means that the actual information is taken from the database and set to the current values of the entity objects. ClientWins means that the database information is set to the original values of the entity objects, and thus the database values will be overwritten with the next SaveChanges. The second parameter of the Refresh() method is either a   
collection of entity objects or a single entity object. You can decide the refresh behavior entity by entity:
 
                    
                
 
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号