title: LINQ to Entities does not recognize the method
body: <p>I'm getting the following error when trying to do a linq query:</p>
  
  <blockquote>
    <p>LINQ to Entities does not recognize the method 'Boolean
    IsCharityMatching(System.String, System.String)' method, and this
    method cannot be translated into a store expression.</p>
  </blockquote>
  
  <p>I've read lots of previous questions where people get the same error, and if I understand this correctly it's because LINQ to Entities requires the whole linq query expression to be translated to a server query, and therefore you can't call an outside method in it. I haven't been able to convert my scenario into something that works yet, and my brain is starting to melt down, so I was hoping someone could point me in the right direction. We're using Entity Framework and the specification pattern (and I'm new to both).</p>
  
  <p>Here's the code that uses the specification:</p>
  
  <pre><code>ISpecification&lt;Charity&gt; specification = new CharitySearchSpecification(charityTitle, charityReference);
  
  charities = charitiesRepository.Find(specification).OrderBy(p =&gt; p.RegisteredName).ToList();
  </code></pre>
  
  <p>Here's the linq expression:</p>
  
  <pre><code>public System.Linq.Expressions.Expression&lt;Func&lt;Charity, bool&gt;&gt; IsSatisfied()
  {
      return p =&gt; p.IsCharityMatching(this.charityName, this.charityReference);
  }
  </code></pre>
  
  <p>Here's the IsCharityMatching method:</p>
  
  <pre><code>public bool IsCharityMatching(string name, string referenceNumber)
  {
      bool exists = true;
  
      if (!String.IsNullOrEmpty(name))
      {
          if (!this.registeredName.ToLower().Contains(name.ToLower()) &amp;&amp;
              !this.alias.ToLower().Contains(name.ToLower()) &amp;&amp;
             !this.charityId.ToLower().Contains(name.ToLower()))
          {
              exists = false;
          }
      }
  
      if (!String.IsNullOrEmpty(referenceNumber))
      {
          if (!this.charityReference.ToLower().Contains(referenceNumber.ToLower()))
          {
              exists = false;
          }
      }
  
      return exists;
  }
  </code></pre>
  
  <p>Let me know if you need any more information.</p>
  
  <p>Many thanks,</p>
  
  <p>Annelie</p>