首页 新闻 搜索 专区 学院

nhibernate2.1.2.4000运行时该字符串未被识别为有效的布尔值。

0
[待解决问题]

环境:nhibernate2.1.2.4000, VS2008,mssqlserver2000,

hibernate.cfg.xml:方言信息:<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>

正常查询、操作正常。

出错部分的代码:

string strHql = "From RepairService rs inner Join rs.Reservation rv Where rv." + fieldName + " Like '%" + nameLike + "%'";
if (orderBy.Trim() != "")
strHql += " Order By " + orderBy;
return _session.CreateQuery(strHql).List<RepairService>();



关联查询时执行的条件能查询出结果时(符合like条件)就出错,不能查询出结果(查询不满足like条件)是就不出错。

我把sql语句拿到查询分析器中运行正常,所以很纳闷。

错误信息:

该字符串未被识别为有效的布尔值。

说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.FormatException: 该字符串未被识别为有效的布尔值。

源错误:

行 26:             if (orderBy.Trim() != "")
行 27: strHql += " Order By " + orderBy;
行 28: return _session.CreateQuery(strHql).List<RepairService>();
行 29: }
行 30: }


源文件: E:\MyWork\Rock\Trunck\RockBLL\CustServiceBll\RepairServiceBo.cs    行: 28

堆栈跟踪:

[FormatException: 该字符串未被识别为有效的布尔值。]   
System.Boolean.Parse(String value) +7663730
System.String.System.IConvertible.ToBoolean(IFormatProvider provider) +15
System.Convert.ToBoolean(Object value) +28
NHibernate.Type.BooleanType.Get(IDataReader rs, Int32 index) +36
NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String name) +92
NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String[] names, ISessionImplementor session, Object owner) +31
NHibernate.Type.AbstractType.Hydrate(IDataReader rs, String[] names, ISessionImplementor session, Object owner) +19
NHibernate.Persister.Entity.AbstractEntityPersister.Hydrate(IDataReader rs, Object id, Object obj, ILoadable rootLoadable, String[][] suffixedPropertyColumns, Boolean allProperties, ISessionImplementor session) +680
NHibernate.Loader.Loader.LoadFromResultSet(IDataReader rs, Int32 i, Object obj, String instanceClass, EntityKey key, String rowIdAlias, LockMode lockMode, ILoadable rootPersister, ISessionImplementor session) +276
NHibernate.Loader.Loader.InstanceNotYetLoaded(IDataReader dr, Int32 i, ILoadable persister, EntityKey key, LockMode lockMode, String rowIdAlias, EntityKey optionalObjectKey, Object optionalObject, IList hydratedObjects, ISessionImplementor session) +135
NHibernate.Loader.Loader.GetRow(IDataReader rs, ILoadable[] persisters, EntityKey[] keys, Object optionalObject, EntityKey optionalObjectKey, LockMode[] lockModes, IList hydratedObjects, ISessionImplementor session) +287
NHibernate.Loader.Loader.GetRowFromResultSet(IDataReader resultSet, ISessionImplementor session, QueryParameters queryParameters, LockMode[] lockModeArray, EntityKey optionalObjectKey, IList hydratedObjects, EntityKey[] keys, Boolean returnProxies) +156
NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) +704 NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) +70
NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) +102

[ADOException: could not execute query[ select repairserv0_.MaintenanceId as Maintena1_186_0_, reservatio1_.MaintenanceId as Maintena1_182_1_,
  repairserv0_.ArrivedDate as ArrivedD2_186_0_, repairserv0_.CompletedDate as Complete3_186_0_, repairserv0_.RepairAddr as RepairAddr186_0_,
  repairserv0_.RepairType as RepairType186_0_, repairserv0_.RepairMan as RepairMan186_0_, repairserv0_.RepairRemark as RepairRe7_186_0_,
  repairserv0_.HasCompleted as HasCompl8_186_0_, repairserv0_.InfoUploaded as InfoUplo9_186_0_, reservatio1_.RegionName as RegionName182_1_,
  reservatio1_.MachineNo as MachineNo182_1_, reservatio1_.CustName as CustName182_1_, reservatio1_.LinkMan as LinkMan182_1_,
  reservatio1_.LinkPhone as LinkPhone182_1_, reservatio1_.ReservMan as ReservMan182_1_, reservatio1_.ReservDate as ReservDate182_1_,
  reservatio1_.RepairDate as RepairDate182_1_, reservatio1_.RepairAddr as RepairAddr182_1_, reservatio1_.CustRemark as CustRemark182_1_,
  reservatio1_.FailurePreDeter as Failure12_182_1_ from CustServ_RepairService repairserv0_ inner join CustServ_Reservation
  reservatio1_ on repairserv0_.MaintenanceId=reservatio1_.MaintenanceId where reservatio1_.RegionName like '%%' ]
[SQL: select repairserv0_.MaintenanceId as Maintena1_186_0_, reservatio1_.MaintenanceId as Maintena1_182_1_, repairserv0_.ArrivedDate as ArrivedD2_186_0_,
  repairserv0_.CompletedDate as Complete3_186_0_, repairserv0_.RepairAddr as RepairAddr186_0_, repairserv0_.RepairType as RepairType186_0_,
  repairserv0_.RepairMan as RepairMan186_0_, repairserv0_.RepairRemark as RepairRe7_186_0_, repairserv0_.HasCompleted as HasCompl8_186_0_,
  repairserv0_.InfoUploaded as InfoUplo9_186_0_, reservatio1_.RegionName as RegionName182_1_, reservatio1_.MachineNo as MachineNo182_1_,
  reservatio1_.CustName as CustName182_1_, reservatio1_.LinkMan as LinkMan182_1_, reservatio1_.LinkPhone as LinkPhone182_1_,
  reservatio1_.ReservMan as ReservMan182_1_, reservatio1_.ReservDate as ReservDate182_1_, reservatio1_.RepairDate as RepairDate182_1_,
  reservatio1_.RepairAddr as RepairAddr182_1_, reservatio1_.CustRemark as CustRemark182_1_, reservatio1_.FailurePreDeter as Failure12_182_1_
  from CustServ_RepairService repairserv0_ inner join CustServ_Reservation reservatio1_ on repairserv0_.MaintenanceId=reservatio1_.MaintenanceId
  where reservatio1_.RegionName like '%%']]
NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) +196
NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters) +18
NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet`1 querySpaces, IType[] resultTypes) +79
NHibernate.Hql.Ast.ANTLR.Loader.QueryLoader.List(ISessionImplementor session, QueryParameters queryParameters) +47
NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.List(ISessionImplementor session, QueryParameters queryParameters) +231
NHibernate.Engine.Query.HQLQueryPlan.PerformList(QueryParameters queryParameters, ISessionImplementor session, IList results) +353
NHibernate.Impl.SessionImpl.List(String query, QueryParameters queryParameters, IList results) +205 NHibernate.Impl.SessionImpl.List(String query, QueryParameters parameters) +182
NHibernate.Impl.QueryImpl.List() +165 Rock.BLL.CustServiceBll.RepairServiceBo.Query(String fieldName, String nameLike, String orderBy, Boolean isAsc) in E:\MyWork\Rock\Trunck\RockBLL\CustServiceBll\RepairServiceBo.cs:28
WebSite.CustService.RepairServiceList.BindData() in E:\MyWork\Rock\Trunck\WebSite\CustService\RepairServiceList.aspx.cs:54
WebSite.CustService.RepairServiceList.btnQuery_Click(Object sender, EventArgs e) in E:\MyWork\Rock\Trunck\WebSite\CustService\RepairServiceList.aspx.cs:31
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
常绍新的主页 常绍新 | 菜鸟二级 | 园豆:212
提问于:2011-10-06 16:31
< >
分享
所有回答(2)
0

前面加 select rs

沉默的糕点 | 园豆:1786 (小虾三级) | 2011-10-07 13:20

加过select rs,运行时报一样的错误。

支持(0) 反对(0) 常绍新 | 园豆:212 (菜鸟二级) | 2011-10-07 14:01

@常绍新:查询结构中,那个Property声明为Bool,检查他的返回结果,是不是1,0 或者 是 yes,no,只有符合这几种形式的字符串或者数值,才能正确转为bool

支持(0) 反对(0) 沉默的糕点 | 园豆:1786 (小虾三级) | 2011-10-07 14:04
0

竟然连个有用的参考意见都没有人给出一下。
最后还是自己通过一步步的查看nhibernate的源代码解决了问题:是bool值保存成数据库char数据之后,再读取时的问题。

常绍新 | 园豆:212 (菜鸟二级) | 2011-10-08 21:44
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册