Skip to content

Instantly share code, notes, and snippets.

@JakeGinnivan
Created October 3, 2012 03:11
Show Gist options
  • Save JakeGinnivan/3824738 to your computer and use it in GitHub Desktop.
Save JakeGinnivan/3824738 to your computer and use it in GitHub Desktop.
var predicate = PredicateBuilder.True<Person>();
if (filderOptions.FirstName != null)
predicate = predicate.AndAlso(p=>p.FirstName == "Alex");
if (filderOptions.SomeNullable.HasValue)
predicate = predicate.AndAlso(p=>p.SomeProp == filterOptions.SomeNullable.Value);
var where = queryable.Where(predicate);
// will create an expresion which looks like this: p => true && p.FirstName == "Alex" && p.SomeProp == filterOptions.SomeNullable.Value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment