title: how to use a delegate to get by name a CompiledQuery
body: <p>I'm trying to find and run a CompiledQuery given the name. How do I access the compiled query by name and how do I then invoke the delegate?</p>
  
  <p>Here's as far as I can get - I get the error 'Error binding to target method'</p>
  
  <pre><code>public class ActivityRepository
  {
      private readonly ActivityDataContext _db;
  
      public ActivityRepository()
      {
          _db = new ActivityDataContext();
      }
  
      public static Func&lt;ActivityDataContext, int, IQueryable&lt;ProjectObject&gt;&gt;
          GetCompiledLatestProjects = CompiledQuery.Compile
              ((ActivityDataContext db, int projectId) =&gt;
               from c in db.projectObjects
               where c.projectId == projectId
               select c);
  
      public static Func&lt;ActivityDataContext, Guid, IQueryable&lt;Report&gt;&gt;
          GetCompiledReports = CompiledQuery.Compile
              ((ActivityDataContext db, Guid itemId) =&gt;
               from c in db.Reports
               where c.reportObjectId == itemId
               select c);
  </code></pre>
  
  <p>// Other compiled queries ommitted, but the results are IQueryable objects that implement a common interface IProjectObject</p>
  
  <pre><code>    delegate IQueryable&lt;IProjectObject&gt; MyDelegate();
  
      static MyDelegate GetByName(object target, string methodName)
      {
              return (MyDelegate)Delegate.CreateDelegate
                  (typeof(MyDelegate), target, methodName);
      }
  
      public IList&lt;Results&gt; GetResults(string reportName)
      {
              IQueryable&lt;ProjectObject&gt; projectItems = GetLatestProjectObjects(projectId, quantity);
          foreach (projectObject o in projectItems)
          {
              MyDelegate del = GetByName(this, reportName);
               var dbReport = (IProjectObject) GetCompiledReports(_db, o.itemId).FirstOrDefault();
  // add results to List and return
           }
       }
  }
  </code></pre>