Using Delphi record inside the class for the data

In a project I have many http requests running in separate threads that return query data in xml from a service out of my control. Till now I use an xml parser to transform them to Delphi record types.
I was thinking to use aurelius to have the possibility to use more than one type of databases and have them also in a mobile app for tablets.
Aurelius uses and manipulates class objects and I was wondering a class like the following can be used and how can be used:
Type Dtest=record
id:integer;
nam:string;
end;
type Ttest=class
private
Ftest:Dtest;
public
property id:integer read Ftest.id write Ftest.id;
property name:string read Ftest.nam write Ftest.nam;
end;
Should I put the attributes for Aurelius in proprties section? Is there an other solution?
In this example we have 2 properties but the usual is to have 10 to 50 in my records and to copy a record is much faster than each variable separate in creation/copy of the class for aurelius and usually I use arrays of records.
Thank you in advance

Unfortunatly XData do not support Record's serialization. I have a feature request for that: 2460: Add support for Record types

You can vote for it if find usefull.

1 Like

You may use any kind of Filed / Property datatypes, since they're not auto-or-manually mapped with Aurelius attributes (if you're automapping, declare [Transient] to your customized-class/record fields). You may manipuate them through any methods, or properties' read/write declarations.
Aurelius persistency will take care just of the persistency-mapped fields.
You should declare any needed properties to use, and make methods to wrap/unwrap it's content after/before Aurelius read/write operations. Maybe into manage Blob fields or other mapped fields with supported datatypes.

Ej.:


MyEntity := myobjmanager.Find<TestEntity>(1);
MyEntity.UnWrapXMLContent; // will take the content from a persisted field, and expand to your customized field
ShowMessage(MyEntity.Test.Nam);
MyEntity.Test.Nam := 'NewName';
MyEntity.WrapXMLContent; // will take the content from your customized field and wrap to an Aurelius mapped persistent field
myobjmanager.Flush(MyEntity);
1 Like

If working with Aurelius entities, by default XData will try to serialize your Fields unless you tell not to using [XDataExcludeProperty] attribute.The same way you have to use [XDataProperty] attibute to any property you want serialized. Ex:

  [Entity]
  [Automaping]
  TSomeAureliusEntity = class
  private
     FId: Integer;
     [XDataExcludeProperty]
     FName: string;
  private
    procedure SetName(const AName: string);
  public
    property Id: Integer read FId write FId;
    [XDataProperty]
    property Name: string read FName write SetName;
  end;

This way (de)serialization with work on FId field and Name property.

Regards,

1 Like

I voted. I usually prefer not to use automapping to be sure.

1 Like

The same way I thought I should use.
A question I have is what Aurelius will use and keep outside the class object that can be changed by the wrap procedures. But I believe Aurelius has not a mechanism to be informed on-line by the content change. It is just "sleeping" between Find and Flush.

The unwrapped content will be held by Aurelius field/properties that are already mapped to database and tracked by Aurelius.