title: Workarounds for using custom methods/extension methods in LINQ to Entities
body: <p>I have defined a GenericRepository class which does the db interaction.   </p>
  
  <pre><code> protected GenericRepository rep = new GenericRepository();
  </code></pre>
  
  <p>And in my BLL classes, I can query the db like:  </p>
  
  <pre><code>public List&lt;Album&gt; GetVisibleAlbums(int accessLevel)
  {
      return rep.Find&lt;Album&gt;(a =&gt; a.AccessLevel.BinaryAnd(accessLevel)).ToList();  
  }  
  </code></pre>
  
  <p>BinaryAnd is an extension method which checks two int values bit by bit. e.g. <code>AccessLevel=5</code> => <code>AccessLevel.BinaryAnd(5)</code> and <code>AccessLevel.binaryAnd(1)</code> both return true.  </p>
  
  <p>However I cannot use this extension method in my LINQ queries. I get a runtime error as follows:<br>
  <code>LINQ to Entities does not recognize the method 'Boolean BinaryAnd(System.Object, System.Object)' method, and this method cannot be translated into a store expression.</code>  </p>
  
  <p>Also tried changing it to a custom method but no luck. What are the workarounds?  </p>
  
  <p>Should I get all the albums and then iterate them through a foreach loop and pick those which match the AccessLevels?</p>