Skip to content

Instantly share code, notes, and snippets.

@ungood
Created April 26, 2012 14:53
Show Gist options
  • Save ungood/2500145 to your computer and use it in GitHub Desktop.
Save ungood/2500145 to your computer and use it in GitHub Desktop.
Example of why methods are better
// This is really elegant with methods, but really, really ugly with query expression
public IQueryable<User> SearchUsers(string firstName, string lastName)
{
var query = getUserQuery();
if(!string.IsNullOrEmpty(firstName))
query = query.Where(user => user.FirstName == firstName);
if(!string.IsNullOrEmpty(lastName))
query = query.Where(user => user.LastName == lastName);
return query;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment