You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm running this linq statement, but it's erroring as not all the SQL parameters are being presented to SQL server, I have been debugging through the nhibernate source and the culprit is partially RemoveUnusedCommandParameters(), but I could do with some help in diagnosing it.
The C# code uses listContactGroupId twice within the linq statement, and that seems to confuse things.
listContactGroupId = new List<int>() { 7, 14, 21, 28 };
var res = dbObject.Count(x => (x.EnquiryContactGroupId.HasValue &&
listContactGroupId.Contains(x.EnquiryContactGroupId.Value)) || (x.ApplicationContactGroupId.HasValue && listContactGroupId.Contains(x.ApplicationContactGroupId.Value)));
The SQL Looks like this
select (count(*)) as col_0_0_ from EnquiryApplicationContactDetail_V venquiryap0_ where (venquiryap0_.EnquiryContactGroupId is not null) and (venquiryap0_.EnquiryContactGroupId in (@p0 , @p1 , @p2 , @p3)) or (venquiryap0_.ApplicationContactGroupId is not null) and (venquiryap0_.ApplicationContactGroupId in (@p4 , @p5 , @p6 , @p7))
But when presented to the SQL server, parameter values @p4->@P7 are missing.
The parameters go missing at the method RemoveUnusedCommandParameters(), there is a line that removes the duplicates
var assignedParameterNames = new HashSet<string>(formatter.AssignedParameterNames);
The formatter.AssignedParmetersNames, rather than being @p0, @p1, @p2, @p3,@P4, @p5, @p6, @P7 it's @p0, @p1, @p2, @p3, @p0, @p1, @p2, @p3, so it ends up with @p0, @p1, @p2, @p3
It's got something to do with nhibernate.sqlcommand.parameter.ParameterPosition which assignes the @p[n] parameter name.
Can anyone shed any light on how it generates the parameter names?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi,
I'm running this linq statement, but it's erroring as not all the SQL parameters are being presented to SQL server, I have been debugging through the nhibernate source and the culprit is partially RemoveUnusedCommandParameters(), but I could do with some help in diagnosing it.
The C# code uses listContactGroupId twice within the linq statement, and that seems to confuse things.
The SQL Looks like this
select (count(*)) as col_0_0_ from EnquiryApplicationContactDetail_V venquiryap0_ where (venquiryap0_.EnquiryContactGroupId is not null) and (venquiryap0_.EnquiryContactGroupId in (@p0 , @p1 , @p2 , @p3)) or (venquiryap0_.ApplicationContactGroupId is not null) and (venquiryap0_.ApplicationContactGroupId in (@p4 , @p5 , @p6 , @p7))
But when presented to the SQL server, parameter values @p4->@P7 are missing.
The parameters go missing at the method RemoveUnusedCommandParameters(), there is a line that removes the duplicates
var assignedParameterNames = new HashSet<string>(formatter.AssignedParameterNames);
The formatter.AssignedParmetersNames, rather than being @p0, @p1, @p2, @p3,@P4, @p5, @p6, @P7 it's @p0, @p1, @p2, @p3, @p0, @p1, @p2, @p3, so it ends up with @p0, @p1, @p2, @p3
It's got something to do with nhibernate.sqlcommand.parameter.ParameterPosition which assignes the @p[n] parameter name.
Can anyone shed any light on how it generates the parameter names?
Thanks,
Tat.
Beta Was this translation helpful? Give feedback.
All reactions