EntitySpaces™ Hierarchical Support

The EntitySpaces Hierarchical Template uses the foreign keys in your database to automatically build the hierarchical object model. First, the standard templates generate the Collections and Entities. Then, the Hierarchical Template generates a partial class that hooks them all up in a hierarchical fashion.

EntitySpaces will automatically save down the hierarchical tree from Parent to Child.  This process is iterative, so calling save on an EntitySpaces Northwind CustomersCollection (custs.Save()) will, also, save all changes to custs.OrdersCollectionByCustomerID, which will in turn save any changes to OrderDetailsCollectionByOrderID. If a Parent has an auto-incrementing key, then that is retrieved and filled in to the foreign key column for you. Everything is handled in the right order, so a Parent will not be deleted before the related Children, or added after related Child records. This prevents foreign key constraints from being violated in the database.

To prevent endless loops, EntitySpaces does not automatically save up the hierarchical tree. To help you determine whether a particular hierarchical sub-object is upstream or down, the default generated names for upstream sub-objects will start with the prefix "UpTo".

The hierarchical properties are lazy-loaded and cached. If, after changes are saved to the database, you need to refresh the cache, set the hierarchical property to null (Nothing in VB.NET). It will be re-loaded from the database on next use.