title: Reuse a LINQ To Entities statement
body: <p>I have the following <code>Select</code> expression that will be performed database-side:</p>
  
  <pre><code>        var model = new ProductListViewModel()
          {
              Products = products
                  .Select(q =&gt; new ProductViewModel()
                  {
                      // Other mapping
                      Name = q.LanguageKey.LanguageValues.FirstOrDefault(p =&gt; p.LanguageKeyID == currentLanguageID &amp;&amp; p.Active).Value,
                  })
                  .OrderBy(q =&gt; q.Name)
          };
  </code></pre>
  
  <p>As you can see, the Name part is quite long, and other part of my program also use the same logic. Therefore, I would like to reuse it (not entire Select statement, just the Name mapping part).</p>
  
  <p>I tried to write a function that only use the entity:</p>
  
  <pre><code>public static string GetProductName(Product product, int languageID)
  {
      return product.LanguageKey.LanguageValues.AsQueryable()
          .FirstOrDefault(q =&gt; q.LanguageID == languageID &amp;&amp; q.Active).Value;
  }
  </code></pre>
  
  <p>However, on calling the method, I (obviously) receive the error</p>
  
  <blockquote>
    <p>LINQ to Entities does not recognize the method {X} method, and this method cannot be translated into a store expression</p>
  </blockquote>
  
  <p>I have searched through many articles on StackOverflow, but most solve the problem of reusing entire Select expression. Is it possible to reuse it? Or do I have to create database Stored Procedure or Function?</p>