title: Creating a common predicate function
body: <p>Firstly, I am not sure what terms to use to ask this question, which is probably why I have not found an answer from searching myself.</p>
  
  <p>So I am working with Linq to SQL (C#, .Net 4) and I want to get a list of all users that match a criteria, the basics of which I would do something like this:</p>
  
  <pre><code>var users = DataContext.Users.Where(x =&gt; x.Criteria1 == "something");
  </code></pre>
  
  <p>but in this case there are a few fields I want to match, the thing is these particular fields are a common check and I would like to be able to create a dedicating function that I can use within any of my user queries to check for this match.</p>
  
  <p>To try and explain that a bit better lets give an example: Lets say a user has 5 flags, and I want a common check to see if <em>any</em> of those flags are set. So I could write my query like so:</p>
  
  <pre><code>var users = DataContext.Users.Where(x =&gt; x.Flag1 || x.Flag2 || x.Flag3 || x.Flag4 || x.Flag5);
  </code></pre>
  
  <p>But what I would like to do is seperate out that "5 flag check" so I can use it in other queries too, ultimately I would like to use something like:</p>
  
  <pre><code>var users = DataContext.Users.Where(x =&gt; x.Criteria1 == "something" &amp;&amp; CheckForFlags(x));
  </code></pre>
  
  <p>I have tried this by having a function like this:</p>
  
  <pre><code>static bool CheckForFlags(User user)
  {
     return user.Flag1 || user.Flag2 || user.Flag3 || user.Flag4 || user.Flag5;
  }
  </code></pre>
  
  <p>but I get an error: </p>
  
  <blockquote>
    <p>"Method 'Boolean CheckForFlags(User)' has no supported translation to
    SQL."</p>
  </blockquote>
  
  <p>...which makes sense, but it there something I can do to make this work the way I want it to? Or is this a restriction because I am using Linq to SQL and is in fact something that would work with Linq to Objects?</p>