I need to add a read-only field that does not exist in my database table.
I want the field to show up in my entity but not saved to the database. It's a calculated field only.
I tried something like this:
[Transient]
Property Onhand: Double Read GetOnhand;
I must be missing something with the [Column] or maybe it cannot be done. Not finding anything in the docs.
wlandgraf
(Wagner Landgraf)
February 14, 2024, 2:18am
2
And then what happened? You can do that.
There is just no need for a Transient
attribute, they apply only to fields.
Gave me an error that the column was undefined.
I deleted the project so I don't have the exact error message anymore.
Appears there needs to be a column defined. Did not know how to do that because then it says the column is missing in the database table.
wlandgraf
(Wagner Landgraf)
February 14, 2024, 11:08am
4
There is no obligation for entity classes to have all members mapped. Please provide minimal detailed information - the full class declaration, the exact error message, etc. so we can provide better information about what might be happening.
Hi Wagner,
I'm having the same problem. See details below. FullName is not appearing in Swagger.. The only difference I can see from examples in the manual is that my Entity is linked to a table. I am using NexusDB.
Thanks,
Ken
[Entity]
[Table('Clients')]
[Id('FGUID', TIdGenerator.Guid)]
TClients = class
private
[Column('"GUID"', [TColumnProp.Required])]
FGUID: TGuid;
[Column('LastName', [], 30)]
FLastName: Nullable<string>;
[Column('FirstName', [], 20)]
FFirstName: Nullable<string>;
function GetFullName: string;
public
property GUID: TGuid read FGUID write FGUID;
property LastName: Nullable<string> read FLastName write FLastName;
property FirstName: Nullable<string> read FFirstName write FFirstName;
property FullName: String read GetFullName;
end;
function TClients.GetFullName:String;
begin
Result:=FirstName.Value + ' ' + LastName.Value;
end;
wlandgraf
(Wagner Landgraf)
February 22, 2024, 11:40am
6
Hi @Randall_Ken ,
You must explicitly tell XData you want the property to be in JSON:
https://doc.tmssoftware.com/biz/xdata/guide/json.html#aurelius-entities
i.e., add [XDataProperty]
attribute to the new property.
Thanks. I have made the following change but still can't see it in Swagger. Anything else missing?
[XDataProperty]
property FullName: String read GetFullName;
1 Like
wlandgraf
(Wagner Landgraf)
February 22, 2024, 12:00pm
8
Do you see it in JSON response/request?
Have you also added XData.Model.Attributes
unit to the uses clause?
2 Likes
I was not using unit Xdata.model.Attributes. It's working when I include it.
1 Like
Randall_Ken
(Ken Randall)
February 22, 2024, 12:37pm
10
I suggest that your next book is XData for Idiots
Sorry, one more question. In the function is it possible to access a value from an associated entity that uses lazy loading?
Randall_Ken
(Ken Randall)
February 23, 2024, 10:43am
12
I have resolved this. I have to put any function last in the select otherwise the other entities values are not available.
1 Like
system
(system)
Closed
February 24, 2024, 10:43am
13
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.