'Use JSON_ARRAYAGG with Entity Framework Core
I am trying to use JSON_ARRAYAGG(JSON_OBJECT(...))
in Entity Framework Core but I don't know much how to trick Entity Framework Core to use this function with a custom IQueryable<T>
.
Does anybody have any simple example how this can be achieved ?
I can not build a raw query because the IQueryable
is built dynamically based on params, but my idea was to first build the IQueryable<T>
and then somehow combine that with the given functions. Lets take a simple example of what I want to achieve:
var people = await db.People.Select(x => new Person { Name = x.Name, Surname = x.Surname }).ToListAsync();
This will translate to:
select name, surname from people;
I want to have:
select JSON_ARRAYAGG(JSON_OBJECT("name", name, "surname", surname) from people;
One solution is to get the query from the IQueryable
and do a nasty replace on the final string, but this does not seem a very good solution.
Is there any way I can modify the list of params on runtime without using replace function ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|