|
|
|
|
|
by fixprix
387 days ago
|
|
C# can turn lambdas into expression trees at runtime allowing libraries like EF to transform code like `db.Products.Where(p => p.Price < 100).Select(p => p.Name);` right to SQL by iterating the structure of that code. JavaScript ORMs would be revolutionized if they had this ability. |
|
In languages that don't have expression inspection capabilities you have to replace the `(p) => p.Price < 100` part with something that is possible for the language to inspect.
Normally it's strings or something using a builder pattern.
For example, in TypeORM:
And in Mongoose: The LINQ-ish version would be: --Similarly, for Ruby on Rails:
Ruby's Sequel overloads operators to have a more natural syntax: But the "lambda" syntax would be: