title: Passing lambda expression as parameter
body: <p>I've got a few tables that all have the same column <code>domainID</code> which basically just controls what data gets displayed on which website, as they share a database.</p>
  
  <p>So when I go to databind a table to a control I would need to create a large switch to handle the different LINQ queries. I would like to create a utility method which takes the table type as a parameter and then return a where clause based on a column in passed table.</p>
  
  <pre><code>public static IEnumerable&lt;T&gt; ExecuteInContext&lt;T&gt;(
                 IQueryable&lt;T&gt; src)
          {
               int domain = 1;//hard coded for example
  
               return src.Where(x =&gt; x.DomainID == domain);//Won't work, has to be a way to do this.            
          }
  </code></pre>
  
  <p>I'm stuck on the return code. You can't simply construct a where clause like I currently am because it doesn't know what table i'm talking about.</p>
  
  <p>I'm trying to call that first method like this:</p>
  
  <pre><code>using (DataClasses1DataContext db = new DataClasses1DataContext())
          {
  
              var q = Utility.ExecuteInContext(db.GetTable&lt;item&gt;());
  
              Repeater1.DataSource = q;
              Repeater1.DataBind();
          }
  </code></pre>
  
  <p>I hope this explains what I'm trying to do.</p>
  
  <p><strong>Edit:</strong> BrokenGlass's answer solved my problem. I would like to add that you need to open up your .dbml.cs file and extend the table/class with your interface. I also wanted to point out that the project wouldn't build if my column was nullable, it said it wasn't the same return type as my interface.</p>