14

2 つのクラス (Request と RequestDetail) があります。Linq To NHibernate結合によって 2 つのクラス間でクエリを実行する必要があります。

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、Result に実行時エラーが発生します。例外のメッセージは次のとおりです。Specified method is not supported.

スタックトレース :

   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)

なんで?

4

2 に答える 2

28

バグかもしれません。

問題の回避策は次のとおりです。

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();
于 2012-11-16T05:33:30.860 に答える
9

流暢な記法で:

var q = session.Query<Request>()
        .Join(session.Query<RequestDetail>(), request => request.Id, detail => detail.Id, (request, detail) => new {
            r = request,
            d = detail
        })
        .Where(rd => rd.r.State == "Init" && rd.d.Purpose.Contains("Purpose Sample"))
        .Select(rd => rd.r)
        .ToList();
于 2017-01-03T12:56:40.893 に答える