Reputation: 81
I have a code like this:
var organisations = Uow.Query<Organisation>()
.Where(x => x.PersonOrganisationRoles.Any(por =>
por.Person.FirstName != null &&
por.Person.FirstName.ToLower().Contains(searchFragmentLower)));
So there is a bridging table between Organisation Person and Role. This query is trying to find orgs that have people with a FirstName containing the string.
The problem is when I run it I get:
Cannot use Person[FirstName <> NULL] as part of a logical expression in an Any or All expression
How can I check for null
?
Upvotes: 1
Views: 56
Reputation: 2511
Looks like something is complaining about the SQL that Linq is generating
try moving the null check into a where clause before running the any
var organisations = Uow.Query<Organisation>().
Where(x => x.PersonOrganisationRoles.Where(por => por != null && por.Person != null && por.Person.FirstName != null).Any(por => phr.Person.FirstName.ToLower().Contains(searchFragmentLower)));
Upvotes: 0