Metaprogramming without templates
SealabJaster
sealabjaster at gmail.com
Mon Jun 21 14:15:27 UTC 2021
On Monday, 21 June 2021 at 13:18:21 UTC, Stefan Koch wrote:
> ...
Exciting, even if the end code looks like a complete hack!
Another thing: Entity Framework, when you give it something like:
```csharp
int age = 20; // Any external variable
MyDbContext.People.Where(person => person.Age >= age);
```
It's able to determine that `age` is an external variable, so
essentially a parameter, and generates a prepared statement like:
```sql
SELECT * FROM people WHERE age >= $1;
```
And it will then automatically forward whatever's in `age` into
parameter $1.
This is of course a very niche use-case, but it's one of the
things that makes Entity Framework so fluent to use (i.e. your
queries are written in normal C#, but are executed on the
database instead of in the application's memory). Of course it
falls back to client-side evaluation if it can't translate things.
This gets more complex the more conditions you tack on, as well
as things like
[.Include](https://docs.microsoft.com/en-us/ef/core/querying/related-data/eager).
This doesn't necessarily need the ability to rewrite the AST, but
as you said, simply generate based off of the reflection of the
AST.
And there's likely a lot more use cases outside of this example.
But I'm now wondering what other things might be possible @_@
More information about the Digitalmars-d
mailing list