title: Type member support in LINQ-to-Entities?
body: <p>I have an MVC3 project using the Entity Framework model in which I've marked up a class like this:</p>
  
  <pre><code>public partial class Product
  {
      public bool IsShipped
      {
          get { /* do stuff */ }
      }
  }
  </code></pre>
  
  <p>and which I want to use in a LINQ expression:</p>
  
  <pre><code>db.Products.Where(x =&gt; x.IsShipped).Select(...);
  </code></pre>
  
  <p>however, I get the following error:</p>
  
  <blockquote>
    <p>System.NotSupportedException was unhandled by user code   Message=The
    specified type member 'IsShipped' is not supported in LINQ to Entities.
    Only initializers, entity members, and entity navigation properties
    are supported.   Source=System.Data.Entity</p>
  </blockquote>
  
  <p>I've googled but not found anything definitive about this usage to I tried:</p>
  
  <pre><code>public partial class Product
  {
      public bool IsShipped()
      {
          /* do stuff */
      }
  }
  
  db.Products.Where(x =&gt; x.IsShipped()).Select(...);
  </code></pre>
  
  <p>but then I get:</p>
  
  <blockquote>
    <p>System.NotSupportedException was unhandled by user code   Message=LINQ
    to Entities does not recognize the method 'Boolean IsShipped()' method,
    and this method cannot be translated into a store expression.<br>
    Source=System.Data.Entity</p>
  </blockquote>
  
  <p>there's functionality there that I don't want to build into the LINQ query itself... what's a good way to handle this?</p>
  
  <p><strong>* update *</strong></p>
  
  <p>Darin makes the valid point that whatever is done in the implementation of <code>IsShipped</code> would need to be converted to a SQL query and the compiler probably doesn't know how to do it, thus retrieving all objects into memory seems the only choice (unless a direct query to the database is made).  I tried it like this:</p>
  
  <pre><code>IEnumerable&lt;Product&gt; xp = db.Quizes
      .ToList()
      .Where(x =&gt; !x.IsShipped)
      .Select(x =&gt; x.Component.Product);
  </code></pre>
  
  <p>but it generates this error:</p>
  
  <blockquote>
    <p>A relationship multiplicity constraint violation occurred: An
    EntityReference can have no more than one related object, but the
    query returned more than one related object. This is a non-recoverable
    error.</p>
  </blockquote>
  
  <p>though curiously this works:</p>
  
  <pre><code>IEnumerable&lt;Product&gt; xp = db.Quizes
      .ToList()
      .Where(x =&gt; x.Skill.Id == 3)
      .Select(x =&gt; x.Component.Product);
  </code></pre>
  
  <p>why would that be?</p>
  
  <p><strong>* update II *</strong></p>
  
  <p>sorry, that last statement doesn't work either...</p>
  
  <p><strong>* update III *</strong></p>
  
  <p>I'm closing this question in favour of pursuing a solution as suggested here to flatten my logic into a query - the discussion will move to <a href="https://stackoverflow.com/questions/7787625/flattening-a-loop-with-lookups-into-a-single-linq-expression">this new post</a>.  The second alternative, to retrieve the entire original query into memory, is likely unacceptable, but the third, of implementing the logic as a direct query to the database, remain to be explored.</p>
  
  <p>Thanks everyone for the valuable input.</p>