NHibernate查询问题(我想是类型转换)

时间:2014-11-17 10:34:08

标签: c# linq nhibernate

我有LINQ问题。我有一个类似的查询。

IQueryable<ConstructionProgress> mainTable = (from constProg in session.QueryEx<ConstructionProgress>(null)
     join landmark in session.QueryEx<LandMarks>(null) on constProg.MileStone equals landmark.Marker
     Where landmark.Name.Equals("Land Mark 1") && constProg.StartVal >= startValue && constProg.EndVal <= endValue
     select new ConstructionProgress
     {
          MileStone = constProg.MileStone, 
          Distance = constProg.Distance / 1000,
          StartVal = constProg.StartVal,
          EndVal = constProg.EndVal
     };

&#34; ConstructionProgress&#34;表包含以米为单位的数据(距离)。上面的查询为我将其转换为公里。所以现在当我尝试以下内容时:

var finalResult = from activity in session.QueryEx<BuiltActivity>(null)
    join constProg in mainTable  on activity.Distance equals constProg.Distance
            where activity.StartTime >= startTime && activity.FinishTime <= finishTime
            select activity;

finalresult查询给出了一个错误,表明不支持数据转换。我正在使用NHibernate,映射是完美的。请帮帮我。我怎样才能摆脱错误。

我得到的例外情况如下:

  

System.NotSupportedException {&#39;不支持指定的方法。&#39;}

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.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.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at ConstManagement.Acme.DbServices.Dao.Daos.BuiltActivityDao._GetActivityData(ISession session, Int32 startValue, Int32 endValue, DateTime startTime, DateTime finishTime)
   at ConstManagement.Acme.DbServices.Dao.Daos.BuiltActivityDao.<>c__DisplayClass1a.<ActivityData>b__17(ISession session)
   at ConstManagement.NHib.NhDaoBase.Execute[TResult](Func`2 action) in d:\Test\ConstructionManagement\Project\Framework\ConstManagement.NHib\NhDaoBase.cs:line 75

0 个答案:

没有答案