2 ms·
Yes and no, the LINQ syntax being coherent between IEnumerable<> and IQueryable<> hides a lot of good magic. IEnumerable<> is regular in-memory lambdas/streams
by whizzter 2y ago
Yes and no, the LINQ syntax being coherent between IEnumerable<> and IQueryable<> hides a lot of good magic.
IEnumerable<> is regular in-memory lambdas/streams, same what you find in many places.
IQueryable<> relies on the LINQ expressions, those CAN be JIT compiled for direct execution, but the fact that they are data-objects is what allows the translation to SQL and execution on the server rather than locally and can give massive gains since processing can be done where the data lives.
- whizzter 2y agoFor reference, to achieve what IQueryable does with 100% normal code in JavaScript you need something like Qustar that was posted here a month ago. Regular transform code in JS (Like IEnumerable) const ids = users.filter(user => user.age<18).map(user => user.id); IQueryable like to be transformed to the server: const ids = users.filter(user => user.age.lt(18)).map(user => user.id); In C# it'd look identical, but in JS or Java this would be achieved via proxy-object hacks (the .lt() function in the filter instead of the < operator and the .id property getter for the user map to send a flag under the hood for the mapping function). https://github.com/tilyupo/qustar https://github.com/tilyupo/qustar