0
votes
 string hql = "from Customer as c left outer join fetch c.Orders" 
 + "where c.CustomerId=:id";

 using(Session)
 {
    return  Session.CreateQuery(hql).SetInt32("id",id).List<Customer>();
 }

when I excute the code, there is an exception like this:

EagerLoadCustomerByIdThroughFetchTest : FailedNHibernate.Hql.Ast.ANTLR.QuerySyntaxException : 引发类型为“Antlr.Runtime.MismatchedTokenException”的异常。 near line 1, column 56 在 NHibernate.Hql.Ast.ANTLR.ErrorCounter.ThrowQueryException() 在 NHibernate.Hql.Ast.ANTLR.HqlParseEngine.Parse() 在 NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(String queryString, String collectionRole, Boolean shallow, IDictionary2 filters, ISessionFactoryImplementor factory) 在 NHibernate.Engine.Query.HQLStringQueryPlan.CreateTranslators(String hql, String collectionRole, Boolean shallow, IDictionary2 enabledFilters, ISessionFactoryImplementor factory) 在 NHibernate.Engine.Query.HQLStringQueryPlan..ctor(String hql, String collectionRole, Boolean shallow, IDictionary2 enabledFilters, ISessionFactoryImplementor factory) 在 NHibernate.Engine.Query.HQLStringQueryPlan..ctor(String hql, Boolean shallow, IDictionary2 enabledFilters, ISessionFactoryImplementor factory) 在 NHibernate.Engine.Query.QueryPlanCache.GetHQLQueryPlan(String queryString, Boolean shallow, IDictionary`2 enabledFilters) 在 NHibernate.Impl.AbstractSessionImpl.GetHQLQueryPlan(String query, Boolean shallow) 在 NHibernate.Impl.AbstractSessionImpl.CreateQuery(String queryString) 在 Data.NhibernateSample.EagerLoadCustomerByIdThroughFetch(Int32 id) 位置 DelayLoadTest.cs: line 80 在 NhibernateDataAcessTest.NhibernateSampleFixture.EagerLoadCustomerByIdThroughFetchTest() 位置 LazyLoad.cs: line 73

what is wrong in my code ,thank you

1

1 Answers

0
votes

You SQL is malformed, there is no space between: "...c.Orders" + "where...".