This project has moved and is read-only. For the latest updates, please go here.

Remote.Linq for JavaScript

Mar 10, 2015 at 11:26 PM
Edited Mar 10, 2015 at 11:31 PM
It might be handy to having a JavaScript library for composing linq expressions and run remote queries to load data from a REST service. However, there are a few points to be clarified first, before thinking about to use or build such a JavaScript library:
  • Is it actually the right approach to allow web-clients to run arbitrary queries against the back-end?
  • If yes, what measure need to be taken to accurately protect the backend (REST service and data store)?
    ▫ Authorization (with various level of granularity)
    ▫ Configurable throttling (e.g. max results)
    ▫ Complexity of the queries (joins, full-table-scans, etc.)
    ▫ …
Thanks for any constructive input.
Mar 11, 2015 at 3:49 PM
As I was the one asking for this, here is my input:
  • Is it actually the right approach to allow web-clients to run arbitrary queries against the back-end?
Yes, otherwise OData would be the wrong approach
  • if yes, what measure need to be taken to accurately protect the backend (REST service and data store)?
I think this should be left to the backend developer. I use property read/write access authorization which has nothing to do with LINQ, it's generic for any object access.

There RELINQ which does this kind of stuff, but it's old, not active and terrible documented (and implemented IMHO). I don;t think we should create expressions on JSSide, but rather use the RELINQ approach of sending an expression string (like DataSource.OfType("Customer").Where(x=>x.Name=="Foo").ToList()). This string would be send to the server and the server would parse it and creating the expression tree.
May 28, 2015 at 5:17 PM
Edited Jul 14, 2015 at 8:06 PM
Sorry for the delayer answer. I had to spend some time to get up-to-date with current js frameworks.

Thanks for your suggestions. It would be nice to provide some sort of js remote query library. However, I currently won’t have the capacity required to create it. Maybe if someone else could contribute….

I’ve had a look at breeze.js which seems to do a good job. You can write nice queries like this:
query = new breeze.EntityQuery()
    .from("Products")
    .orderBy("name")
    .where("price", ">", 100);

manager.executeQuery(query)
    .then(function(data){
        ko.applyBindings(data);
    }).fail(function(err) {
        alert("Query failed: " + err);
    });
breeze supports also saving back changes, it’s quite powerful. The downside for read-only data might be that you have to provide metadata about your data model. And I believe it’s not possible to actually execute dynamic queries with joins, projections, grouping, etc. like you can with remote.linq