我正在尝试执行此HQL查询:
"from Order as order join order.Services as services"
但是无论何时我正在使用联接,我都会遇到这个例外:
[QuerySyntaxException: Exception of type 'Antlr.Runtime.NoViableAltException' was thrown. near line 1, column 20]
NHibernate.Hql.Ast.ANTLR.ErrorCounter.ThrowQueryException() +118
NHibernate.Hql.Ast.ANTLR.HqlParseEngine.Parse() +490
NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(String queryString, String collectionRole, Boolean shallow, IDictionary`2 filters, ISessionFactoryImplementor factory) +89
NHibernate.Engine.Query.HQLStringQueryPlan.CreateTranslators(String hql, String collectionRole, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory) +88
NHibernate.Engine.Query.HQLStringQueryPlan..ctor(String hql, String collectionRole, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory) +71
NHibernate.Engine.Query.HQLStringQueryPlan..ctor(String hql, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory) +50
NHibernate.Engine.Query.QueryPlanCache.GetHQLQueryPlan(String queryString, Boolean shallow, IDictionary`2 enabledFilters) +241
NHibernate.Impl.AbstractSessionImpl.GetHQLQueryPlan(String query, Boolean shallow) +179
NHibernate.Impl.AbstractSessionImpl.CreateQuery(String queryString) +160
BL.Queue.GetOrders() in c:\Yayasoft\YTour\YTour\BL\Queues\Queue.cs:66
YTourWeb.Test.Page_Load(Object sender, EventArgs e) in c:\Yayasoft\YTour\YTour\YTourWeb\Test.aspx.cs:16
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
System.Web.UI.Control.OnLoad(EventArgs e) +92
System.Web.UI.Control.LoadRecursive() +54
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772
当我添加连接(任何连接)时,如果我执行选择而没有连接,则会发生这种情况 两个实体都已映射,因此尝试连接未映射的属性不是问题 任何想法?
答案 0 :(得分:2)
在这种情况下,我会说,order
这个词被错误地评估为ORDER BY
的一部分。尝试使用不同的别名,例如 orderX :
var hql = "from Order as orderX join orderX.Services as services"