Polymorphic queries

Polymorphic queries extend the polymorphic behavior of classes into the persistence layer. What I mean by this is – polymorphism gives us a base type variable that can hold a reference to a derived type and invokes methods from derives types at runtime, NHibernate is capable of loading correct instance of derived type when queried by base type. For instance, if you try to load a Benefit entity by ID from database, but the benefit record in the database corresponds to SkillsEnhancementAllowance, then NHibernate is capable of determining what the actual derived type the record needs to be mapped to (SkillsEnhancementAllowance in this example) and instantiates the correct entity type. We have seen this in Chapter 3, Let's Tell ...

Get Learning NHibernate 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.