I'm executing a query using a subquery like so:
Parent aliasParent = null;
var queryOver = unitOfWork.Session.QueryOver<Parent>(() =>
aliasParent).
WithSubquery.WhereProperty(parent =>
parent.ID).In(QueryOver.Of<Child>().
Where(child => ...).
And(child => child.Parent.ID == aliasParent.ID).
Select(child => child.Parent.ID));
The purpose is to only load Parent entities whose Child entities have
certain criteria.
The query executes correctly, and the resulting SQL is generated correctly.
However, the following error appears in my debugger's output window:
A first chance exception of type 'NHibernate.QueryException' occurred in
NHibernate.dll
This is a trapped exception within NHibernate. I believe NHibernate throws
the exception at one point in the query translation code, when it sees the
alias and doesn't know what to do. Only later does it then trap and
respond to the exception in another part of the translation. This is all
fine, except that by using exception handling in this way results in poorer
performance. The performance impact is not significant unless someone is
executing a lot of these kinds of queries in succession. I estimate that
the query should only take 10 ms to execute, but because of the exception
handling, the query is taking almost 70 ms.
Is it worth reporting an issue over this? It seems to me that using the
exception handling is "by design", and that the performance impact may
already be known and understood.
I've experimented with modifying the NHibernate library, so it would be
possible to submit a patch with the issue, however,
Is there a workaround to the issue other than query the Child entities
directly, fetching the Parent association, and then manually loading a list
like so:
List<Child> children = session.Query<Child>().Where(child =>
...).Fetch(child => child.Parent).ToList();
foreach (Child child in children)
{
if (parents.IndexOf(child.Parent) == -1)
parents.Add(child.Parent);
}
parents.Sort(...);
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/groups/opt_out.