2012-03-28 64 views
0

我是NHibernate的新手,我希望我可以找到一些幫助,以追查我試圖對謂詞使用DateTime比較時收到的轉換錯誤的來源。NHibernate QueryOver轉換錯誤在DB2日期類型

return _session.QueryOver<ShipmentSegment>() 
       .Where(ss => ss.SegmentOrigin == selOrig) 
       // Whenever I add the predicate for the SegmentDate below 
       // I receive a conversion error 
       .And(ss => ss.SegmentDate == selDate) 
       .List<ShipmentSegment>(); 

異常

NHibernate.Exceptions.GenericADOException was unhandled by user code 
    Message=could not execute query 
[ SELECT this_.ajpro# as ajpro1_28_0_, this_.ajleg# as ajleg2_28_0_, this_.ajpu# as ajpu3_28_0_, this_.ajlorig as ajlorig28_0_, this_.ajldest as ajldest28_0_, this_.segdate as segdate28_0_, this_.ajldptwin as ajldptwin28_0_, this_.ajlfrtype as ajlfrtype28_0_, this_.ajlfrdest as ajlfrdest28_0_, this_.ajtpmfst# as ajtpmfst10_28_0_, this_.ajspplan as ajspplan28_0_, this_.ajhload as ajhload28_0_ FROM go52cst.tstshprte this_ WHERE this_.ajlorig = @p0 and this_.segdate = @p1 ] 
    Name:cp0 - Value:WIC Name:cp1 - Value:3/28/2012 12:00:00 AM 

內部異常

Message=A conversion error occurred. 
     Source=IBM.Data.DB2.iSeries 
     ErrorCode=-2147467259 
     MessageCode=111 
     MessageDetails=Parameter: 2. 
     SqlState="" 
     StackTrace: 


- at IBM.Data.DB2.iSeries.iDB2Exception.throwDcException(MpDcErrorInfo 
mpEI, MPConnection conn) 
- at IBM.Data.DB2.iSeries.iDB2Command.openCursor() 
- at IBM.Data.DB2.iSeries.iDB2Command.ExecuteDbDataReader(CommandBehavior 
behavior) 
- at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader() 
- at NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd) 
- at NHibernate.Loader.Loader.GetResultSet(IDbCommand st, Boolean autoDiscoverTypes, Boolean callable, RowSelection selection, 
    ISessionImplementor session) 
- at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) 
- at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor 
    session, QueryParameters queryParameters, Boolean returnProxies) 
- at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) 

我明白什麼可以幫點我在正確的方向。

回答

1

我對這個特定的iSeries異常的經驗來自我爲ADO.NET命令參數列表創建存儲過程類型ADO命令的參數(iDB2TypeParameter)。我不得不明確告訴使用什麼樣的iDB2DbType:iDB2DbType.Date,iDB2DbType.Time或iDB2DbType.TimeStamp。從.NET System.DateTime類型創建參數時,iSeries ADO提供程序不可能知道使用哪種類型的三種類型。

new iDB2Parameter(parameterName, iDB2DbType.Date){ Value = myValue }; 
new iDB2Parameter(parameterName, iDB2DbType.Time){ Value = myValue }; 
new iDB2Parameter(parameterName, iDB2DbType.TimeStamp){ Value = myValue }; 

我意識到你不是像這個例子手動創建你的參數,而是使用NHibernate。所以,我會確保NHibernate的用於DB2/iSeries的LINQ提供程序知道這一點。對於NHibernate來說,這並不意味着什麼,我發現幾乎不可能爲DB2/iSeries找到好的,實體的ORM。