I am a beginner in NHibernate queries. And an easy task enters me into a stupor. Trying to get list of hotels filtering by cityIDs (where the hotels are located in) or all hotels if list of CityiIDs is empty. So, writing:
var q = CurrentSession.CreateQuery(@"from Hotel h where :cityIds is empty or h.City.ID in (:cityIds)").
SetParameterList("cityIds", cityIds);
return q.List<Hotel>().ToList();
But occurs this error:
"Object reference not set to an instance of an object."
at NHibernate.Util.StringHelper.Root(String qualifiedName) at NHibernate.Hql.Ast.ANTLR.Tree.FromElementFactory.AddFromElement() at NHibernate.Hql.Ast.ANTLR.Tree.FromClause.AddFromElement(String path, IASTNode alias) at NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.CreateFromElement(String path, IASTNode pathNode, IASTNode alias, IASTNode propertyFetch) at NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.fromElement() at NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.fromElementList() at NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.fromClause() at NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.unionedQuery() at NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.query() at NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.collectionFunctionOrSubselect() at NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.comparisonExpr() at NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.logicalExpr() at NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.logicalExpr() at NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.logicalExpr()
But if I get away the restriction ":cityIds is empty" from the query - it works well! What's the matter?
Please help to resolve some misunderstanding of HQL expressions