The neat thing about how LINQ to SQL handles expressions is that you can actually build out expressions elsewhere in your code and reference them in your queries. Why don’t you try something like this:
public static class Predicates
{
public static Expression<Func<User, bool>> CheckForFlags()
{
return (user => user.Flag1 || user.Flag2 || user.Flag3 ||
user.Flag4 || user.Flag5);
}
public static Expression<Func<User, bool>> CheckForCriteria(string value)
{
return (user => user.Criteria1 == value);
}
}
Once you have your predicates defined, it’s very easy to use them in a query.
var users = DataContext.Users
.Where(Predicates.CheckForFlags())
.Where(Predicates.CheckForCriteria("something"));