gpt4 book ai didi

c# - 如何在 linq-to-Nhibernate 中使用多个条件连接

转载 作者:可可西里 更新时间:2023-11-01 08:04:28 26 4
gpt4 key购买 nike

我有两个类(Request 和 RequestDetail)。我需要通过联接在两个类之间进行 Linq To NHibernate查询。

var q = SessionInstance.Query<Request>()
.Where(x => x.State == "Init");

var q2 = SessionInstance.Query<RequestDetail>();
q2 = q2.Where(xx => xx.Purpose.Contains("Purpose Sample")); // This line has a error When execution ‍‍`q.ToList()‍`

q = q.Join(q2, request => request.Id, detail => detail.Id, (request, detail) => request);

return q.ToList();

当我将 Where 条件添加到 q2 时,结果出现运行时错误。异常消息是:不支持指定的方法。

堆栈跟踪:

   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.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.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[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)

为什么?

最佳答案

这可能是一个错误。

这是解决您的问题的方法:

var q = (from request in session.Query<Request>()
join detail in session.Query<RequestDetail>() on request.Id equals detail.Id
where request.State == "Init" && detail.Purpose.Contains("Purpose Sample")
select request).ToList();

关于c# - 如何在 linq-to-Nhibernate 中使用多个条件连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13394759/

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