TObjectManager.Replicate and Entity with enum in PK


I have a xData restserver using MSSQL and exe clients where I use Echo to maintain a local SQLite database.
During first startup of client, after Echo has been setup, I use TObjectManager.Replicate<Entity> to get data of some entities over from server to my client. I have one entity (TProjectVolume) that gives me an error that I'm not able to solve.

The entity TProjectVolume differs a bit from my other entities, it has a PK of 2 fields. First field is of type (nvarchar(20)) enumeration, second field is an integer (FK).
During the call TObjectManger.Replicate. The error I get is:

Project SmartStudioPro.exe raised exception class EInvalidCast with message 'Invalid class typecast'.

The error occurs in Aurelius.Engine.ObjectManager, line:

Result := E(InternalMerge(Entity, Explorer.GetEntityType(Entity), DummyMasterObject, ProcessedObjs, TMergeType.Replicate));

TProjectVolume entity definition:

  [Id('FVolume', TIdGenerator.None)]
  [Id('FProjectToolID', TIdGenerator.None)]
  TProjectVolume = class
    [Column('Volume', [TColumnProp.Required], 20)]
    FVolume: TEnumVolume;

    [Column('SortNo', [])]
    FSortNo: Nullable<Double>;

    [Association([TAssociationProp.Lazy, TAssociationProp.Required], CascadeTypeAll - [TCascadeType.Remove])]
    [JoinColumn('ProjectToolID', [TColumnProp.Required], 'ID')]
    FProjectToolID: Proxy<TProjectTool>;
    function GetProjectToolID: TProjectTool;
    procedure SetProjectToolID(const Value: TProjectTool);
    property Volume: TEnumVolume read FVolume write FVolume;
    property SortNo: Nullable<Double> read FSortNo write FSortNo;
    property ProjectToolID: TProjectTool read GetProjectToolID write SetProjectToolID;

The TEnumVolume enumeration:

  // USE DBFieldName = 'Volume' of type NVARCHAR(20)
  [Enumeration(TEnumMappingType.emString, 'NA,HP,AN,LP,TEST,SET1,UNSET1,SET2,UNSET2,SET3,UNSET3')]
  TEnumVolume = (NA, HP, AN, LP, TEST, SET1, UNSET1, SET2, UNSET2, SET3, UNSET3);

Do you have any hints or suggestions to share to help me resolve my issue?

Thank you.

Hi @Olsen_Leif_Eirik,

Are you able to provide the call stack at the moment of the exception, so we can have an idea of from where in the code the exception is being raised?

Sure, please find the CallStack attached.

LEO_CallStack.txt (3.3 KB)

Thank you for the information. We could reproduce it here, and it's indeed a specific issue with Aurelius, when trying to Replicate entities which have enumerated field in their id.

We have fixed this issue internally and next update will include the fix.

1 Like

Wow that was quick, thank you so much Wagner!
Much appreciated, really looking forward to using it.

Leif Eirik

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.