Nhibernate has a nice feature, which I have discovered coincidentally:
public interface IInterface {}
public class Impl1 : IInterface {}
public class Impl2 : IInterface {}
ISession session = sf.OpenSession();
session.QueryOver<IInterface>().List();
This will fetch me all Impl1 ans Impl2 objects (in case those classes are mapped). They need not be mapped as SubClassMaps, which leads me to the conclusion that NHibernate resolves the implementing classes all by itself.
Can anyone send me the link to documentation on this one? I know neither the name nor the technical background of this feature…
Thanks in advance!
Actually, this is just the way NHibernate does inheritance mapping.
In addition to the usage you described, you also have the ability to i.e. define a child collection on an object, using the base type and put any object of inherited type to the collection. For instance, you could have another entity containing a collection of your
IInterfaceobjects:Now you could put any object implementing
IInterfaceintoMyCollection, and NHibernate will persist them (if mapping is correct):However, the actual database usage (generated SQL) depends on the inheritance mapping strategy that you have defined, so get familiar with them first. You can read more in official documentation.