Skip to content

Instantly share code, notes, and snippets.

@saip106
Created September 28, 2017 00:38
Show Gist options
  • Save saip106/801b22ef536e977b58b7503e02c2639c to your computer and use it in GitHub Desktop.
Save saip106/801b22ef536e977b58b7503e02c2639c to your computer and use it in GitHub Desktop.
public Person[] Get(SearchCriteria searchCriteria)
{
using(var dbContext = new MyDbContext())
{
var query = dbContext.Persons;
if(!string.IsNullOrWhitespace(searchCriteria.FirstName))
{
query = query.Where(x => x.FirstName.Contains(searchCriteria.FirstName));
}
if(!string.IsNullOrWhitespace(searchCriteria.Zipcode))
{
query = query.Where(x => x.Zipcode == searchCriteria.Zipcode);
}
return query.ToArray();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment