This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
We have a model with to classes "Base" and "Additional". They have a one-to-one connection and the reference column is placed in "Additional".
The queries will not be executed because wrong SQL is generated:
uow.Bases.Where(b => b.Additional != null && b.Additional.Text == "value");
uow.Bases.Where(b => b.Additional != null).Where(b => b.Additional.Text == "value");
The following query will work:
var a = uow.Bases.Where(b => b.Additional != null).ToList();
a = a.Where(b => b.Additional.Text == "value").ToList();
var x = a.ToList();
This workaround is not an option because we have quite some data to query. Furthermore we cannot change the query to start with "Additional". I will send you an example program via mail.
Regards,
Dennis
|
|
|
Just remove the b.Additional != null clause. This is redundant because b.Additional.Text = "value" will never be true if b.Additional is null, and you don't have to worry about null references because the query is being translated to SQL, not executed on objects. Hence: UnitOfWork.Bases.Where(b => b.Additional.Text == "value") will work fine and give you the same results. |
|
|
Thanks for the info. The example was simplified and we have a situation where we get a Queriable and add our where-clause. The source of the queriable may be a unitofwork but may also be a list or something else. Therefore we have to perform this null-check.
Regards,
Dennis
|
|
|
I've implemented a fix to make the null check safe. It will be in the next nightly build. |
|