I would like to report a bug on NHibernate v3.2.0.GA using IBM.Data.DB2.iSeries.dll (v7.1) reproduction of the error are as follows:
Assuming we have a table USERS consisting of fields USER_ID, FULL_NAME, PASSWORD. NHibernate can easily retrieve all the records by issuing the statement:
Session.CreateCriteria(Of objUsers).List(Of objUsers)();
However, when trying to add a criteria :
Session.CreateCriteria(Of objUsers).Add(Restrictions.InsensitiveLike("FULL_NAME", "john", MatchMode.Anywhere)).List(Of objUsers)();
NHibernate generates an error:
"Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"
Browsing the source code of NHibernate led me to the routine that is causing the error:
File Name: DriverBase.cs
.Select(p => p.ParameterName)
The LINQ query that is been used for removing the unused parameters is removing the used command parameters. The result of
formatter.AssignedParameterNames are "?" for each parameter while the parameter names for cmd.Parameters are "p0, p1" thus
removing all the parameters used or unused for the query. As a temporary fix, I just commented-out the code above and NHibernate
can now successfully retrieve the records given a specified criteria. I think the problem is due to the SQL syntax of DB2 wherein all
parameters are represented with a question mark sign "?". I will also try to analyze the source code to find a solution to this bug.