NHibernate QueryOver with subquery using parent (root) alias = could not resolve property exception

1,061 views
Skip to first unread message

Broken Pipe

unread,
Sep 14, 2016, 11:25:06 AM9/14/16
to nhusers
Also asked at stackoverflow site: http://stackoverflow.com/questions/39493202/nhibernate-queryover-with-subquery-using-parent-root-alias-could-not-resolve

I'm trying to write QueryOver with subquery, which references root query property inside it using this code:
Entity root = null;
var query = Session.QueryOver(() => root);
var subQuery = QueryOver.Of<Entity>();
subQuery.Where((x) => x.Id == root.Id).Select(Projections.RowCount());
query.WithSubquery.WhereValue(0).Eq(subQuery);
query.List();


This doesn't work, because: NHibernate.QueryException: could not resolve property: root of: Entity

Broken Pipe

unread,
Sep 15, 2016, 9:58:00 AM9/15/16
to nhusers
I Figured this out. The exception mensioned, is caught inside NH, and it doesn't break the query. I was debuging code in Visual Studio with enabled "stop on thrown exception" option. And thought I had "only my code" option switched on, for some strange reason exception from NH are shown. My collegue pointed out that line of code with caught exceptions is highlighted in green, and uncaught are yellow.
Reply all
Reply to author
Forward
0 new messages