RichardRoz wrote:
Thanks Otis and Walaa for sticking with me on this. I finally figured out what the problem was. I was simplifying the problem out of my example.
If I query against a non-nullable field in my database, everything works just as you described. However, in my case, the field was nullable. This means the generated entity code defines a Nullable<System.Int32> type for the field. The compiler doesn't allow you to simply provide the nullable field as the Contains() parameter:
where numbers.Contains(o.SomeField)
You have to resolve it to an int first. The solution that works with LLBLGen Pro 2.6 is to simply cast the value:
where numbers.Contains((int)o.SomeField)
I didn't come to this solution quickly since I know that casting a null value in C# will throw an exception. I forgot that the Contains() is being translated (hopefully) to SQL code where comparison between a null value and an int simply results in non-equality.
That's indeed better info
. o.SomeField, nullable or not, should have been handled properly and you should have seen a list of elements. You shouldn't have to cast it, so it could be a bug, however we have added better checkcode for nullable fields to convert them more properly in all possible cases, so also this case. I'll see if I can repro it with a nullable field. I couldn't find a buildnumber of the runtime you're using, so in any case, try with the latest build.
Instead, I tried handling the null values by converting them to a number that I'm sure won't match any element in my numbers list like:
where numbers.Contains(o.SomeField ?? -1)
and
where numbers.Contains(o.SomeField.HasValue ? (int)o.SomeField : -1)
and
where numbers.Contains(o.SomeField == null ? -1 : (int)o.SomeField)
These queries cause the behavior I've been describing i.e. the query has no where clause returning the entire table AND the list is not filtered in memory either!
I'm taking a guess that if the destination data provider isn't SQL Server and can't handle evaluation of null values, it will mean a crash.
Will you be adding support for this case in the near future?
All the best,
Richard.
These all result in a CASE statement, or better: should result in a CASE statement with the construct of the contains call, i.e. an IN query. I'm not sure if the where is simply ignored because the coalesce call or the IIF call wasn't expected, but I'll try.
Anyway, for now, cast it as the query won't care about the nullability anyway: the list of numbers doesn't contain null.