How can I query on the server on a nullable field? I’ve tried several things, but I always get an error that it is not supported. For example:
var lda = connection.LinqRemoteDataAdapter;
var query = from p in lda.GetTable<Products>()
select p;
var products = query.Where(p => (p.Weight ?? 0) > 0).ToList();
var lda = connection.LinqRemoteDataAdapter;
var query = from p in lda.GetTable<Products>()
select p;
var products = query.Where(p => p.Weight > 0).ToList();
but there is no need to because p.Weight > 0 condition alone will do the same and will be faster db-wise.
Remember that this statement is not executed locally - it is just a way of describing some conditions that will be later converted into a SQL statement.
In SQL expression [Weight] > 0 will be True only when [Weight] is not NULL and [Value] is greater than NULL
Coalesce operator is not supported atm. I’ll log an issue to check if it is possible to add its support.
ideally we should support == null and map it to IS NULL? since while the above might work for Weight, chances are there’ll be scenarios where we need to distinguish between NULL and 0…
You are right, the coalesce operator is not needed in this case. I’m not sure why I thought it was required to deal with the nullable and use the coalesce operator. Probably some version of the code gave me an error regarding the nullable, so I assumed this was always the case, but it’s not. Just tested this and it works fine with a simple p.Weight > 0 comparison.