Using an interface for subquery in NHibernate
I usually query interfaces using DetachedCriteria in NHibernate:
DetachedCriteria crit = DetachedCriteria.For<IParent>();
And it works great.
Now I want to create a subquery for the child object like this:
DetachedCriteria subcrit = DetachedCriteria.For<IChild>();
and add it to criteria like this (view, p.Child is actually an alias, but I've simplified it):
crit.Add(LambdaSubquery.Property<IParent>(p => p.Child.ChildID).In(subcrit));
This works if my DetchedCriteria for the child is:
DetachedCriteria subcrit = DetachedCriteria.For<Child>();
but not it for the interface (as above). In this case, I get an exception:
NHibernate.MappingException: No persister for: Domain.Name.Space.IChild
Is this something it should have been, or am I missing some configuration?
a source to share
I don't think you will be able to query the interface in this case, because NHibernate will not be able to find the right implementation class you want to query for. For example, suppose you have another IChild developer named ChildLight (or something that maps to a different table), NHibernate has no direction for which the implementation class is being implemented.
You need to create DetachedCriteria.For <Child> (), not an interface.
a source to share