I want to add a calculated field (or more) to a table query in my REST server in order to send it with XData.
It doesn't matter whether I later have to work with a standard query (REST Get List standard endpoint) or a service function.
The entity list passed with XData must therefore be expanded to include the field.
I got confused with the terms. What is "add a calculated field to a table query in my REST Server"?
Are you using an automatic CRUD endpoint or a service operation endpoint?
Are you building a query component manually server-side?
Are you referring to calculate fields in a query component or in an entity class?
Can you please be more specific, I really didn't understand what you want to achieve, thanks.
It is simple,
As an an example: (dummy example)
A table: Name:String / Quantity:Integer / Price:Float
The client application wants to display a table with : Name, Quantity, Price, AND Total:Float (Total = Quantity * Price) The client application is stupid. The client can only show
The client can use automatic CRUD, but I can also make a service endpoint.
I usually get a TList<TMyEntity>.
But there are only Name,Quantity,Price included.
I'm looking for a quick solution to extend this list with a field/column that is calculated on the server.
And here are the two questions
Where and how to calculate the value (an event in XDataServer or an event in Aurelius)
How to transfer the extended list most easily
Currently I have simply extended the entity with the desired fields (also in the database) and calculate the values in Aurelius with OnInserting/OnUpdating. But I really didn't want to add these fields to the database.
There are a few solutions. First is to add calculated fields to your entity. Just create a Total property, set a getter for it and calculate the total based on the getter. Then make such property available in JSON by adding XDataJsonProperty attribute to it. An example:
Another option is to create your own DTO class (TMyDTOEntity) and return it from a service operation. Then create and fill its properties manually from TMyEntity, and fill in the missing properties accordingly.