这是我的课程的样子:
class User
{
IList<UserRedemptionCode> UserRedemptions;
}
class UserRedemptionCode
{
string Code;
}
class Course
{
IList<CourseRedemptionCode> CourseRedemptions;
}
class CourseRedemptionCode
{
string Code;
string SomeData;
}
我想检索与与用户关联的兑换代码匹配的所有课程。这是我正在进行的当前 IQuerable 调用:
IQueryable<Course> query = Courses.Where(
course => course.CourseRedemptions.Any(
cr => user.UserRedemptions.Any(rc => cr.Code == rc.Code));
但是,这似乎不适用于 NHibernate。我得到这个例外:
System.NotSupportedExceptionSpecified 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.DefaultQueryProvider.PrepareQuery(Expression expression, IQuery& query, NhLinqExpression& nhQuery)
at NHibernate.Linq.DefaultQueryProvider.Execute(Expression expression)
at NHibernate.Linq.DefaultQueryProvider.Execute[TResult](Expression expression)
at Remotion.Linq.QueryableBase`1.GetEnumerator()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Web.Http.Filters.EnumerableEvaluatorFilter.Convert[T](Object input)
at System.Web.Http.Filters.EnumerableEvaluatorFilter.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
at System.Web.Http.Filters.ActionFilterAttribute.CallOnActionExecuted(HttpActionContext actionContext, HttpResponseMessage response, Exception exception)
at System.Web.Http.Filters.ActionFilterAttribute.<>c__DisplayClass4.<System.Web.Http.Filters.IActionFilter.ExecuteActionFilterAsync>b__2(HttpResponseMessage response)
at System.Threading.Tasks.TaskHelpersExtensions.<>c__DisplayClass2e`2.<Then>b__2d(Task`1 t)
at System.Threading.Tasks.TaskHelpersExtensions.ThenImpl[TTask,TOuterResult](TTask task, Func`2 continuation, CancellationToken cancellationToken)
还有另一个问题,在此查询中,我返回了课程列表,但我还需要与用户关联的 CourseRedemptionCode,以便获取 SomeData。
有任何想法吗?还有另一种方法可以进行此查询吗?