0
votes

In my db i have string type field: client_name

I'm trying to perform a search to find client by his name

sclient = (sclient ?? "").ToLower();

var items = session.Query().Where(x => x.Users.name.ToLower().Contains(sclient));

Note that Users.name is a mapped class.

When i perform simple search everything works. Now when i sclient is null the search does not display any items where Client_name is null!

how can I display clients where there name is null after search query?

1
you might want to consider if the current behavior is not more desirable. searching on empty field from application has some risk in security and performance - Tristan

1 Answers

1
votes

If you want to return records, which do contain searched string or their column value is null, this would be the syntax:

var items = session
     .Query<MyEntity>()
     .Where(x => x.Users.name.ToLower().Contains(sclient)
              || x.Users.name == null);

which will do something like this:

// sql generated
WHERE lower(users1_.client_name) like (''%''+@p1+''%'') 
   OR usrs1_.client_name is null