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
If I am performing a query using linq, where there is a list that is used in the expression twice, the generated SQL is malformed.
var listContactGroupId = new List<int>() { 1, 2, 3, 4 };
var res = dbObject.Count(x => (x.EnquiryContactGroupId.HasValue && listContactGroupId.Contains(x.EnquiryContactGroupId.Value)) || (x.ApplicationContactGroupId.HasValue && listContactGroupId.Contains(x.ApplicationContactGroupId.Value)));
It only fills in the parameter for the first OR condition so although it's creates the parameters for @P4 , @p5 , @p6 , @P7, it never gives values, so the error is you must declare the scalar variable @P4
could not execute query
[ select venquiryap0_.EnquiryApplicationContactDetailId as enquiryapplicationcontactdetailid1_150_, venquiryap0_.[Timestamp] as .
<snip>
_ 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)) ]
Name:p1_0_ - Value:1 [Type: NHibernate.Type.Int32Type (SqlType: Int32)] Name:p1_1_ - Value:2 [Type: NHibernate.Type.Int32Type (SqlType: Int32)] Name:p1_2_ - Value:3 [Type: NHibernate.Type.Int32Type (SqlType: Int32)] Name:p1_3_ - Value:4 [Type: NHibernate.Type.Int32Type (SqlType: Int32)]
But if I create a even a reference to that list, and then use it in my query, the variable @p0 - @P7 are all present.
Is this a bug in the defaultQueryProvider?
var listContactGroupId = new List<int>() { 1, 2, 3, 4 };
var listContactGroupId2 = listContactGroupId;
var res = dbObject.Count(x => (x.EnquiryContactGroupId.HasValue && listContactGroupId.Contains(x.EnquiryContactGroupId.Value)) || (x.ApplicationContactGroupId.HasValue && listContactGroupId2.Contains(x.ApplicationContactGroupId.Value)));
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,
If I am performing a query using linq, where there is a list that is used in the expression twice, the generated SQL is malformed.
It only fills in the parameter for the first OR condition so although it's creates the parameters for @P4 , @p5 , @p6 , @P7, it never gives values, so the error is you must declare the scalar variable @P4
But if I create a even a reference to that list, and then use it in my query, the variable @p0 - @P7 are all present.
Is this a bug in the defaultQueryProvider?
Beta Was this translation helpful? Give feedback.
All reactions