src/Shared/EntityFramework/Core/Mapping/Update/Internal/UpdateCommand.cs
// <summary>
// Provides a suggested ordering between two commands. Ensuring a consistent ordering is important to avoid deadlocks
// between two clients because it means locks are acquired in the same order where possible. The ordering criteria are as
// follows (and are partly implemented in the CompareToType method). In some cases there are specific secondary
// reasons for the order (e.g. operator kind), but for the most case we just care that a consistent ordering
// is applied:
// - The kind of command (dynamic or function). This is an arbitrary criteria.
// - The kind of operator (insert, update, delete). See <see cref="ModificationOperator" /> for details of the ordering.
// - The target of the modification (table for dynamic, set for function).
// - Primary key for the modification (table key for dynamic, entity keys for function).
// If it is not possible to differentiate between two commands (e.g., where the user is inserting entities with server-generated
// primary keys and has not given explicit values), arbitrary ordering identifiers are assigned to the commands to
// ensure CompareTo is well-behaved (doesn't return 0 for different commands and suggests consistent ordering).
// </summary>
Provides a suggested ordering between two commands. Ensuring a consistent ordering is important to avoid deadlocks
between two clients because it means locks are acquired in the same order where possible. The ordering criteria are as
follows (and are partly implemented in the CompareToType method). In some cases there are specific secondary
reasons for the order , but for the most case we just care that a consistent ordering
is applied:
The kind of command (dynamic or function). This is an arbitrary criteria.
The kind of operator (insert, update, delete). See  for details of the ordering.
The target of the modification (table for dynamic, set for function).
Primary key for the modification (table key for dynamic, entity keys for function).
If it is not possible to differentiate between two commands , arbitrary ordering identifiers are assigned to the commands to
ensure CompareTo is well-behaved (doesn't return 0 for different commands and suggests consistent ordering).
Provides a suggested ordering between two commands . Ensuring a consistent ordering is important to avoid deadlocks between two clients because it means locks are acquired in the same order where possible . The ordering criteria are as follows ( and are partly implemented in the CompareToType method ) . In some cases there are specific secondary reasons for the order but for the most case we just care that a consistent ordering is applied : The kind of command ( dynamic or function ) . This is an arbitrary criteria . The kind of operator ( insert update delete ) . See for details of the ordering . The target of the modification ( table for dynamic set for function ) . Primary key for the modification ( table key for dynamic entity keys for function ) . If it is not possible to differentiate between two commands arbitrary ordering identifiers are assigned to the commands to ensure CompareTo is well - behaved ( doesn ' t return 0 for different commands and suggests consistent ordering ) .
public int CompareTo(UpdateCommand other)
        {
            if (Equals(other))
            {
                return 0;
            }
            Debug.Assert(null != other, "comparing to null UpdateCommand");
            var result = (int)Kind - (int)other.Kind;
            if (0 != result)
            {
                return result;
            }
            result = CompareToType(other);
            if (0 != result)
            {
                return result;
            }
            unchecked
            {
                if (_orderingIdentifier == 0)
                {
                    _orderingIdentifier = Interlocked.Increment(ref OrderingIdentifierCounter);
                }
                if (other._orderingIdentifier == 0)
                {
                    other._orderingIdentifier = Interlocked.Increment(ref OrderingIdentifierCounter);
                }
                return _orderingIdentifier - other._orderingIdentifier;
            }
        }
public int CompareTo ( UpdateCommand other ) { if ( Equals ( other ) ) { return 0 ; } Debug . Assert ( null != other , " " ) ; var result = ( int ) Kind - ( int ) other . Kind ; if ( 0 != result ) { return result ; } result = CompareToType ( other ) ; if ( 0 != result ) { return result ; } unchecked { if ( _orderingIdentifier == 0 ) { _orderingIdentifier = Interlocked . Increment ( ref OrderingIdentifierCounter ) ; } if ( other . _orderingIdentifier == 0 ) { other . _orderingIdentifier = Interlocked . Increment ( ref OrderingIdentifierCounter ) ; } return _orderingIdentifier - other . _orderingIdentifier ; } }
Provides a suggested ordering between two commands.
Provides a suggested ordering between two commands .
// If the commands are the same (by reference), return 0 immediately. Otherwise, we try to find (and eventually // force) an ordering between them by returning a value that is non-zero. // defer to specific type for other comparisons... // if the commands are indistinguishable, assign arbitrary identifiers to them to ensure consistent ordering
other
UpdateCommand