Adding a generic topological sort for the update pipeline.

EntityKey value could be null. Either add checking for nulls, or consider creating a NullEntityKey sentinel to avoid checking for nulls in multiple places.