我有基本的nhibernate查询利用linq到nhibernate。
我们随机查询停止工作(没有特定的签入包含现在失败的代码)。
尝试调试问题,我将nhibernate探查器附加到代码中。当我启动应用程序时,页面工作正常。当我删除探查器初始化代码时,应用程序再次失败。
我做错了什么?以下是我们看到的例外情况:无法转换类型' System.Boolean'的对象输入 ' System.String'
这是堆栈跟踪:
[InvalidCastException:无法转换类型' System.Boolean' 输入' System.String'。] NHibernate.Type.AbstractStringType.ToString(Object val)in d:\ CSHARP \ NH \的nhibernate \ SRC \ NHibernate的\型号\ AbstractStringType.cs:31
NHibernate.Type.NullableType.ToLoggableString(Object value, ISessionFactoryImplementor工厂) d:\ CSHARP \ NH \的nhibernate \ SRC \ NHibernate的\型号\ NullableType.cs:109
NHibernate.Impl.Printer.ToString(IDictionary`2 namedTypedValues)in d:\ CSHARP \ NH \的nhibernate \ SRC \ NHibernate的\默认地将Impl \ Printer.cs:68
NHibernate.Engine.QueryParameters.LogParameters(ISessionFactoryImplementor 工厂) d:\ CSHARP \ NH \的nhibernate \ SRC \ NHibernate的\引擎\ QueryParameters.cs:225
NHibernate.Engine.Query.HQLQueryPlan.PerformList(QueryParameters queryParameters,ISessionImplementor session,IList results)in d:\ CSHARP \ NH \的nhibernate \ SRC \ NHibernate的\引擎\查询\ HQLQueryPlan.cs:81 NHibernate.Impl.SessionImpl.List(IQueryExpression queryExpression, QueryParameters queryParameters,IList results)in d:\ CSHARP \ NH \的nhibernate \ SRC \ NHibernate的\默认地将Impl \ SessionImpl.cs:652[GenericADOException:无法执行查询[SQL:SQL not available]] NHibernate.Impl.SessionImpl.List(IQueryExpression queryExpression, QueryParameters queryParameters,IList results)in d:\ CSHARP \ NH \的nhibernate \ SRC \ NHibernate的\默认地将Impl \ SessionImpl.cs:662
NHibernate.Impl.SessionImpl.List(IQueryExpression queryExpression, QueryParameters参数) d:\ CSHARP \ NH \的nhibernate \ SRC \ NHibernate的\默认地将Impl \ SessionImpl.cs:634
NHibernate.Impl.ExpressionQueryImpl.List()in d:\ CSHARP \ NH \的nhibernate \ SRC \ NHibernate的\默认地将Impl \ ExpressionQueryImpl.cs:63 NHibernate.Linq.NhQueryProvider.ExecuteQuery(NhLinqExpression nhLinqExpression,IQuery query,NhLinqExpression nhQuery)in d:\ CSHARP \ NH \的nhibernate \ SRC \ NHibernate的\ LINQ的\ NhQueryProvider.cs:78
NHibernate.Linq.NhQueryProvider.Execute(表达式表达式)中 d:\ CSHARP \ NH \的nhibernate \ SRC \ NHibernate的\ LINQ的\ NhQueryProvider.cs:27
NHibernate.Linq.NhQueryProvider.Execute(表达式表达式)中 d:\ CSHARP \ NH \的nhibernate \ SRC \ NHibernate的\ LINQ的\ NhQueryProvider.cs:101
Remotion.Data.Linq.QueryableBase1.GetEnumerator() +138
1来源)+180
System.Linq.Enumerable.Count(IEnumerable
Medrio.Administration.Web.Controllers.UserController.SetupUserTableViewData(字符串 searchString,String newOrderBy,Nullable1 isDesc, Int32 pageIndex, String idOfDivToReplace, IEnumerable
1个users)in C:\ Medrio \ CodeTrunk \ Medrio.Administration \网络\控制器\ UserController.cs:207 Medrio.Administration.Web.Controllers.UserController.Index(字符串 searchString,String orderBy,Nullable1 isDesc, Nullable
1 pageIndex) 在 C:\ Medrio \ CodeTrunk \ Medrio.Administration \网络\控制器\ UserController.cs:53 lambda_method(Closure,ControllerBase,Object [])+240
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller,Object []参数)+14
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext,IDictionary2 parameters) +211
2 参数)+27
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary
System.Web.Mvc.Async&LT;&GT; C_ DisplayClass42.b _41() +28 System.Web.Mvc.Async。&lt;&gt; c_ DisplayClass81.<BeginSynchronous>b__7(IAsyncResult _) +10 System.Web.Mvc.Async.WrappedAsyncResult
1.End()+57 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult) asyncResult)+48
System.Web.Mvc.Async&LT;。&以及c _DisplayClass39.b_ 33() +57 System.Web.Mvc.Async。&lt;&gt; c _DisplayClass4f.b_ 49() +223 System.Web.Mvc.Async。&lt;&gt; c _DisplayClass4f.b_ 49() +223 System.Web.Mvc.Async。&lt;&gt; c _DisplayClass37.b__36(IAsyncResult asyncResult)+10 System.Web.Mvc.Async.WrappedAsyncResult`1.End() 57
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult)+48
System.Web.Mvc.Async。&lt;&gt; c_ DisplayClass2a.b _20()+24
System.Web.Mvc.Async。&lt;&gt; c_ DisplayClass25.b _22(IAsyncResult asyncResult)+102
System.Web.Mvc.Async.WrappedAsyncResult 1.End() +57
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +43
System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +14
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
System.Web.Mvc.Async.WrappedAsyncResult
1.End()+62
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)+57
System.Web.Mvc.Async。&lt;&gt; c_ DisplayClass4.b _3(IAsyncResult ar)+23
System.Web.Mvc.Async.WrappedAsyncResult 1.End() +62
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +47
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +25
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
System.Web.Mvc.Async.WrappedAsyncResult
1.End()+62
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)+47
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)+9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+9629296
System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean&amp; completedSynchronously)+155
如果您对此问题有任何见解,请告诉我们!我很失落!
更新
下面是生成谓词的代码,我们将其传递给与会话交互的方法:
if (string.IsNullOrWhiteSpace(orderBy))
orderBy = "ID";
if (isDesc.HasValue == false)
isDesc = false;
var result = DAORegistry.DaoFactory.UserDAO.FindAll(pageIndex, pageSize, orderBy, isDesc.Value,
((u => string.IsNullOrWhiteSpace(searchString)
|| (u.FirstName.Contains(searchString)
|| u.LastName.Contains(searchString))
|| u.Email.Contains(searchString)
|| u.UserName.Contains(searchString)))
);
下面是UserDAO.FindAll方法:
public IEnumerable<T> FindAll(Expression<Func<T, bool>> predicate)
{
return _session.QueryOver<T>().Where(predicate).Future();
}
note 我正在运行nhibernate 3.0.0.0版。我们正在更新到最新版本。