Skip to main content

Posts

Showing posts from September, 2017

Multiple complex clauses joined with OR operation in where function

How is it possible to filter data based on some set of filters or expressions that should be used with or operation in where clause? For example, there is a class: class DTOFilter { public string Domain { get ; set ; } public string Mobile { get ; set ; } } It is required to filter Users list based on the list of the filters next way: u => ( u . Email . Contains ( filters [ 0 ]. Domain ) && u . PhoneNumber . StartsWith ( filters [ 0 ]. Mobile )) || ( u . Email . Contains ( filters [ 1 ]. Domain ) && u . PhoneNumber . StartsWith ( filters [ 1 ]. Mobile )) || ... But the more usable form would be: db . Users . Where ( filters . Filter < Users , DTOFilter >( ( u , f ) => u . Email . Contains ( f . Domain ) && u . PhoneNumber . StartsWith ( f . Mobile )) . Or ())