Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: Cannot use Linq Where and Select Extension Methods

$
0
0
I am trying to get ClearScript to work with my a Linq data access Layer. I have unit of work object that exposes IQueryable of my various database entities. E.g. IQueryable<Project>

I am trying to write a linq statement to select specific projects from the unit of work using the Where extension method but I get the following message Error: 'System.Linq.IQueryable' does not contain a definition for 'Where'. Similiar errors occur for other extension methods that require Func<> delegates. E.g. Select, OrderBy, etc. Any help on getting this scenario to work would be much appreciated.

Unit Of Work Definition
Public class MyUnitOfWork : UnitOfWorkBase
{
    public IQueryable<Project> Projects { get { return this.Query<Project>(); } }
}
Script Engine Setup
using (var engine = new V8ScriptEngine())
{
    var uow = ContextFactory.GetModuleRepo<MyUnitOfWork>(); //creates unit of work instance
    engine.AddHostType(typeof(Enumerable).FullName, typeof(Enumerable));
    engine.AddHostType(typeof(Queryable).FullName, typeof(Queryable));
    engine.AddHostObject("uow", uow);
    engine.Evaluate(txtScript.Text);
}
Javascript
result = uow.Projects.Where(function(w) {return w.Id == 100;}).ToList();

Viewing all articles
Browse latest Browse all 2297

Trending Articles