JSINQ (Linq for JavaScript library) subqueries (instructions)

I use this library: jsinq .

I want to create a new object using subqueries. For example, in .NET LINQ, I could do something like this:

from a in Attendances where a.SomeProperty = SomeValue select new { .Property1 = a.Property1, .Property2 = a.Property2, .Property3 = (from p in People where p.SomeProperty = a.Property3 select p) } 

so I get a list of ALL people whose Property3 value matches the Property3 value for attendance in the EACH returned in the list.

I have not seen any examples of this in the docs or on the playground . I made a couple of attempts and no luck.

Does anyone know if this is possible and how?

+4
source share
1 answer

I also started working with jslinq while searching for the LINQ-JavaScript library. However, I decided to switch to linq.js, which turned out to be closer to LINQ.NET.

http://linqjs.codeplex.com

http://neue.cc/reference.htm

One of the best parts of the linq.js library is that it contains C # lambda syntax, and you can put subqueries in these lambdas.

For example, take the following linq.js request, which they sent as an example.

 Enumerable.Range(0, 20) .Where("$ % 3 == 0") .Select("value, index => {index:index, value:value * 10}") .WriteLine("$.index + ':' + $.value") 

Computes with the output:

 0:0 1:30 2:60 3:90 4:120 5:150 6:180 

Now here is an example with a subquery:

 Enumerable.Range(0, 20) .Where("$ % 3 == 0") .Select("value, index => {index:index, value:Enumerable.Range(0, 20).Where(\"$ % 3 == 0\").ToArray()}") .WriteLine("$.index + ':' + $.value") 

Return:

 0:0,3,6,9,12,15,18 1:0,3,6,9,12,15,18 2:0,3,6,9,12,15,18 3:0,3,6,9,12,15,18 4:0,3,6,9,12,15,18 5:0,3,6,9,12,15,18 6:0,3,6,9,12,15,18 

This is a trivial example, but it shows that subqueries are possible with linq.js.

+2
source

Source: https://habr.com/ru/post/1305622/


All Articles