Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to use a delegate to get by name a CompiledQuery
    text
    copied!<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>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload