gpt4 book ai didi

c# - 休眠Linq

转载 作者:太空狗 更新时间:2023-10-29 23:11:55 26 4
gpt4 key购买 nike

我正在为 nHibernate 使用旧的 linq 提供程序并耐心等待新的出来。我相信它会减轻我的痛苦。无论如何,我对下面的代码有疑问,因为它生成了一个“对象引用未设置到对象的实例”。该行“c.Disciplines.Any(d => disciplines.Contains(d))”是导致问题。使用这样的语句是否有任何已知问题nHibernate Linq?

var agencies = m_AgencyRepository.Linq;

Discipline[] disciplines = user.Disciplines.ToArray<Discipline>();

return (from c in agencies
where (String.IsNullOrEmpty(criteria.AgencyName) || c.AgencyName.Contains(criteria.AgencyName))
&& (criteria.AgencyType == null || c.AgencyType.AgencyTypeId == criteria.AgencyType)
&& (String.IsNullOrEmpty(criteria.AgencyLevel) || c.AgencyLevel.AgencyLevelId == criteria.AgencyLevel)
&& (c.Disciplines.Any(d => disciplines.Contains(d)))
select c)

堆栈跟踪:

   at NHibernate.Loader.Criteria.CriteriaQueryTranslator.GetEntityName(ICriteria subcriteria, String propertyName)
at NHibernate.Loader.Criteria.CriteriaQueryTranslator.GetType(ICriteria subcriteria, String propertyName)
at NHibernate.Loader.Criteria.CriteriaQueryTranslator.GetTypeUsingProjection(ICriteria subcriteria, String propertyName)
at NHibernate.Criterion.InExpression.GetTypedValues(ICriteria criteria, ICriteriaQuery criteriaQuery)
at NHibernate.Criterion.Junction.GetTypedValues(ICriteria criteria, ICriteriaQuery criteriaQuery)
at NHibernate.Loader.Criteria.CriteriaQueryTranslator.GetQueryParameters()
at NHibernate.Criterion.SubqueryExpression.InitializeInnerQueryAndParameters(ICriteriaQuery criteriaQuery)
at NHibernate.Criterion.SubqueryExpression.ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary`2 enabledFilters)
at NHibernate.Criterion.Junction.ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary`2 enabledFilters)
at NHibernate.Loader.Criteria.CriteriaQueryTranslator.GetWhereCondition(IDictionary`2 enabledFilters)
at NHibernate.Loader.Criteria.CriteriaJoinWalker..ctor(IOuterJoinLoadable persister, CriteriaQueryTranslator translator, ISessionFactoryImplementor factory, CriteriaImpl criteria, String rootEntityName, IDictionary`2 enabledFilters)
at NHibernate.Loader.Criteria.CriteriaLoader..ctor(IOuterJoinLoadable persister, ISessionFactoryImplementor factory, CriteriaImpl rootCriteria, String rootEntityName, IDictionary`2 enabledFilters)
at NHibernate.Impl.SessionImpl.List(CriteriaImpl criteria, IList results)
at NHibernate.Impl.CriteriaImpl.List(IList results)
at NHibernate.Impl.CriteriaImpl.List()
at NHibernate.Impl.CriteriaImpl.UniqueResult()
at NHibernate.Linq.Visitors.ImmediateResultsVisitor`1.HandleAggregateCall(MethodCallExpression call)
at NHibernate.Linq.Visitors.ImmediateResultsVisitor`1.VisitMethodCall(MethodCallExpression call)
at NHibernate.Linq.Visitors.ExpressionVisitor.Visit(Expression exp)
at NHibernate.Linq.Visitors.NHibernateExpressionVisitor.Visit(Expression exp)
at NHibernate.Linq.Visitors.ImmediateResultsVisitor`1.GetResults(MethodCallExpression expr)
at NHibernate.Linq.Visitors.RootVisitor.HandleImmediateResultsCall(MethodCallExpression call)
at NHibernate.Linq.Visitors.RootVisitor.VisitMethodCall(MethodCallExpression expr)
at NHibernate.Linq.Visitors.ExpressionVisitor.Visit(Expression exp)
at NHibernate.Linq.Visitors.NHibernateExpressionVisitor.Visit(Expression exp)
at NHibernate.Linq.Visitors.NHibernateQueryTranslator.Translate(Expression expression, QueryOptions queryOptions)
at NHibernate.Linq.NHibernateQueryProvider.Execute(Expression expression)
at NHibernate.Linq.QueryProvider.System.Linq.IQueryProvider.Execute[T](Expression expression)
at System.Linq.Queryable.Count[TSource](IQueryable`1 source)
at PPSS.Services.AgencyRepository.List(AgencyListCriteria criteria, Int32& total) in C:\Development\PPSS\PPSS.Services\Services\Agency\AgencyRepository.cs:line 57
at PPSS.Models.AgencyViewData..ctor(AgencyListCriteria criteria) in C:\Development\PPSS\PPSS\Domains\Maintenance\ViewModels\AgencyViewData.cs:line 26
at PPSS.Controllers.AgencyController.Index(AgencyListCriteria criteria) in C:\Development\PPSS\PPSS\Domains\Maintenance\Controllers\AgencyController.cs:line 34
at lambda_method(ExecutionScope , 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__DisplayClassa.<InvokeActionMethodWithFilters>b__7()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)

最佳答案

改变

user.Disciplines.ToArray<Discipline>()

user.Disciplines.ToList<Discipline>()

NHibernate 理解对具体 List 对象的 .Contains() 调用。

关于c# - 休眠Linq,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/924211/

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