I had a script in Oracle where I need to combine a substring of a part of a column with a list of values. I used the sqlfunction projection to apply the substring in the required column and added this projection as part of the restriction in the section. The following are simplified criteria that I wrote for this.
ICriteria criteriaQuery = session.CreateCriteria<Meeting>()
.Add(Restrictions.In(
Projections.SqlFunction(
"substring",
NHibernateUtil.String,
Projections.Property("Code"),
Projections.Constant(1),
Projections.Constant(3)),
new string[] { "D01", "D02" }))
.Add(Restrictions.In("TypeId", meetingTypes));
The problem I ran into was that the generated SQL was incorrect, where the number of parameters registered for the statement is greater than the statement actually used, and some parameters are repeated even if they are not used. This leads to a failure of the instruction with the message - ORA-01036: invalid variable name / number. Generated request
SELECT this_.Meeting_id as Meeting1_0_2_, .....
WHERE substr(this_.Mcs_Main, :p0, :p1) in (:p2, :p3)
and this_.Meeting_Type_Id in (:p4, :p5);
:p0 = 1, :p1 = 3, :p2 = 1, :p3 = 3, :p4 = 'D02', :p5 = 'D03', :p6 = 101, :p7 = 102
p2 p3 p0, p1, - .
, , , , , .
, In, , Equal Restriction, In.