Linq To LLBLGen contains with nullable column

Posts   
 
    
yowl
User
Posts: 266
Joined: 11-Feb-2008
# Posted on: 25-May-2022 21:58:58   

Hi,

LLBLGen 5.8 adapter

What is the recommended way to get the following sql where clause :

declare 
@i int
set @i = null
select 1 where  @i in (1,2)

There is a memory Contains as per https://www.llblgen.com/Documentation/5.9/LLBLGen%20Pro%20RTF/Using%20the%20generated%20code/Linq/gencode_linq_generalusage.htm#queryable-contains

However @i is nullable so, if that were a nullable column we would have in C#

var someInMemoryArray = new int[] {1,2};

q.Where(a => someInMemoryArray.Contains(a.SomeNullableIntColumn)

However C# does not like that due to the mix of int[] and IQueryable<int?>, i.e. int and int?:

Severity    Code    Description Project File    Line    Suppression State
Error CS1929 'int[]' does not contain a definition for 'Contains' and the best extension method overload 
'Queryable.Contains<int?>(IQueryable<int?>, int?)' requires a receiver of type 'IQueryable<int?>'   

Do I just copy the in memory array to another int?[] first?

Thanks,

yowl
User
Posts: 266
Joined: 11-Feb-2008
# Posted on: 25-May-2022 22:00:59   

q is an IQueryable<EntityWithANullableIntFieldEntity>

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 26-May-2022 02:04:48   

The error is stating that int[] doesn't have a definition for Contains(). Try using a List<int>

List<int> someInMemoryList = someInMemoryArray.ToList();

q.Where(a => someInMemoryList.Contains(a.SomeNullableIntColumn)
yowl
User
Posts: 266
Joined: 11-Feb-2008
# Posted on: 27-May-2022 15:02:52   

Contains is in Linq.Enumerable.

But the behavior that we have with LLBLGen is consistent with Linq, so I'll just close this. It just threw me a bit as copying the array is not great, but I understand why its necessary.