title: How to create a Generic lambda expression. Many of my entities perform the same Lambda expression predicate
body: <p>I use Entity Framework 4.<br />
  How can I perform a Generic Where Lambda Clause.?<br /></p>
  
  <p>I Have many Entity that need the same Where Query.</p>
  
  <pre><code>public Func&lt;SupplierTypeText, bool&gt; GetLmbLang()
  {
      return (p =&gt; p.LangID == 1);
  }
  
  
  public Func&lt;ProductText, bool&gt; GetLmbLang()
  {
      return (p =&gt; p.LangID == 1);
  }
  
  
  public Func&lt;CategoryText, bool&gt; GetLmbLang()
  {
      return (p =&gt; p.LangID == 1);
  }
  </code></pre>
  
  <p>I would like to have a generic method like</p>
  
  <pre><code>//public interface IRepository&lt;T&gt; : IRepository&lt;T&gt; where T : class
  public Func&lt;T, bool&gt; GenericGetLmbLang()
  {
      return (p =&gt; p.LangID == 1);
  }
  </code></pre>
  
  <p>For the  moment, I hardcoded Language ID == 1, that will be from the user session to make it dynamic.
  <br />
  That's would be very usefull if I Can directly call the GetLmbLang() Directly in the Where clause.</p>
  
  <pre><code> var ViewModel = _db.Suppliers.Select(model =&gt; new
              {
                  model,
                  SupType = _db.SupplierTypeTexts.Where(a =&gt; GenericGetLmbLang())
              });
  </code></pre>
  
  <p><strong>------UPDATE--------</strong>
  <br />
  Here is what I Trying and nothing works.<br />
  <br />
  My Base Class</p>
  
  <pre><code> public class BaseGenericModel
      {
          public int LangID { get; set; }
  
          public Func&lt;BaseGenericModel, bool&gt; GetLmbLang()
          {
              return (p =&gt; p.LangID == 1);
          }
  
      }
  </code></pre>
  
  <p>My interface is</p>
  
  <pre><code>   public interface IBaseRepository&lt;T&gt; where T : BaseGenericModel
     {
          Func&lt;T, bool&gt; GetLmbLang();
     }
  
  
     public class BaseRepository&lt;T&gt; : IBaseRepository&lt;T&gt; where T : BaseGenericModel
     {
  
         public Func&lt;T, bool&gt; GetLmbLang()
         {
            return (p =&gt; p.LangID == 1);
         }
     }
  </code></pre>
  
  <p>I Can't call this repository form my SupplierTypeText,ProductText,CategoryText. That's doesn't work. </p>