gpt4 book ai didi

nhibernate - linq to nhibernate 和 mvc 应用程序中的急切加载问题

转载 作者:行者123 更新时间:2023-12-04 00:11:00 28 4
gpt4 key购买 nike

你好我有以下代码使用带有 linq 的 nhibernate 3.0 从我的数据库中检索数据-

public IQueryable<myEntity> getEntityWithChild
{
get { return _currentSession.Query<myEntity>().Fetch(c => c.myOtherEntity); }
}

当我尝试将其传递给 View 时,出现以下错误,但不是很具体。当我不急于使用以下内容加载时,这工作得很好 -

public IQueryable<myEntity> getEntityWithChild
{
get { return _currentSession.Query<myEntity>(); }
}

但每次其他实体将被延迟加载时,我都会创建一个单独的查询。之前有没有人见过这个,也许能给我指明正确的方向。感谢您的任何想法。

System.NotSupportedException was unhandled by user code
Message=Specified method is not supported.
Source=NHibernate
StackTrace:
at NHibernate.Hql.Ast.ANTLR.PolymorphicQuerySourceDetector.GetClassName(IASTNode querySource)
at NHibernate.Hql.Ast.ANTLR.PolymorphicQuerySourceDetector.Process(IASTNode tree)
at NHibernate.Hql.Ast.ANTLR.AstPolymorphicProcessor.Process()
at NHibernate.Hql.Ast.ANTLR.AstPolymorphicProcessor.Process(IASTNode ast, ISessionFactoryImplementor factory)
at NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(IASTNode ast, String queryIdentifier, String collectionRole, Boolean shallow, IDictionary`2 filters, ISessionFactoryImplementor factory)
at NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(String queryIdentifier, IQueryExpression queryExpression, String collectionRole, Boolean shallow, IDictionary`2 filters, ISessionFactoryImplementor factory)
at NHibernate.Engine.Query.HQLExpressionQueryPlan.CreateTranslators(String expressionStr, IQueryExpression queryExpression, String collectionRole, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory)
at NHibernate.Engine.Query.HQLExpressionQueryPlan..ctor(String expressionStr, IQueryExpression queryExpression, String collectionRole, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory)
at NHibernate.Engine.Query.HQLExpressionQueryPlan..ctor(String expressionStr, IQueryExpression queryExpression, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory)
at NHibernate.Engine.Query.QueryPlanCache.GetHQLQueryPlan(IQueryExpression queryExpression, Boolean shallow, IDictionary`2 enabledFilters)
at NHibernate.Impl.AbstractSessionImpl.GetHQLQueryPlan(IQueryExpression queryExpression, Boolean shallow)
at NHibernate.Impl.AbstractSessionImpl.CreateQuery(IQueryExpression queryExpression)
at NHibernate.Linq.NhQueryProvider.PrepareQuery(Expression expression, IQuery& query, NhLinqExpression& nhQuery)
at NHibernate.Linq.NhQueryProvider.Execute(Expression expression)
at NHibernate.Linq.NhQueryProvider.Execute[TResult](Expression expression)
at Remotion.Data.Linq.QueryableBase`1.GetEnumerator()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at vCalWebCalendar.Controllers.HomeController.Hearings() in C:\Users\carl.PAMB.000\Documents\Visual Studio 2010\Projects\Calendar\Calendar\Controllers\HomeController.cs:line 41
at lambda_method(Closure , ControllerBase , Object[] )
at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClassd.<InvokeActionMethodWithFilters>b__a()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
InnerException:

最佳答案

根据 Mike Hadlow 的博客文章 NHibernate Linq Eager Fetching ,

Note that if you want to mix Fetch with other clauses, Fetch must always come last.

您问题中的查询是您正在执行的确切查询吗?

关于nhibernate - linq to nhibernate 和 mvc 应用程序中的急切加载问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4136990/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com