Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Lambda .Contains() on multiple properties

We are using the following to generate a search query (using NHibernate).

GetAll(x => x.Username.ToUpper().Contains(SEARCH)).ToList();

Is it possible to do a search (Contains) for multiple properties, something like ...

    GetAll(x => x.Username.ToUpper().Contains(SEARCH) 
        && x => x.Firstname.ToUpper().Contains(SEARCH) 
        && x => x.Lastname.ToUpper().Contains(SEARCH)).ToList();

Using C#

like image 934
Hugusta Avatar asked Feb 11 '11 23:02

Hugusta


1 Answers

GetAll(x => x.Username.ToUpper().Contains(SEARCH) 
        && x.Firstname.ToUpper().Contains(SEARCH) 
        && x.Lastname.ToUpper().Contains(SEARCH)).ToList();

I'd imagine you'd want to do a search on OR though:

GetAll(x => x.Username.ToUpper().Contains(SEARCH) 
        || x.Firstname.ToUpper().Contains(SEARCH) 
        || x.Lastname.ToUpper().Contains(SEARCH)).ToList();
like image 141
Nick Spiers Avatar answered Oct 04 '22 22:10

Nick Spiers