Converting circular structure to JSON error (again)

Hi I don't known why this error happen, i think this is something wrong in my TXDataWebDataSet settings, in querystring or other BUT if i start my application, load master/details data and simple edit master or detail table like this

  If Not (DM0.wdROrd.State In [dsEdit,dsInsert])Then

I have the error showed in the image


Attached the datamodule of the web client app (open this with winRAR please) see tables wdTOrd (master) and wdROrd (detail) and the entity structure of the server. Tell me if you need other thing please like JSON map. How can retrieve it ?

Thx (7.9 KB)

  [Id('FPK_1', TIdGenerator.IdentityOrSequence)]
  TORD_RISTO_T = class
    [Column('PK_1', [TColumnProp.Required])]
    FPK_1: Integer;

    [Column('CAUSALE', [], 3)]
    FCAUSALE: Nullable<string>;

    [Column('TIPO_DOC', [], 5)]
    FTIPO_DOC: Nullable<string>;

    [Column('VEN_POS', [TColumnProp.Required])]
    FVEN_POS: Boolean;

    [Column('DATA_DOC', [])]
    FDATA_DOC: Nullable<TDateTime>;

    [Column('NUM_DOC', [], 20)]
    FNUM_DOC: Nullable<string>;

    [Column('COD_PC', [], 5)]
    FCOD_PC: Nullable<string>;

    [Column('COD_OPER', [], 5)]
    FCOD_OPER: Nullable<string>;

    [Column('TIPO_SOGG', [], 3)]
    FTIPO_SOGG: Nullable<string>;

    [Column('COD_CLIFOR', [], 20)]
    FCOD_CLIFOR: Nullable<string>;

    [Column('COD_CLI_GFE', [], 20)]
    FCOD_CLI_GFE: Nullable<string>;

    [Column('RAG_SOC', [], 50)]
    FRAG_SOC: Nullable<string>;

    [Column('INDIRIZZO', [], 50)]
    FINDIRIZZO: Nullable<string>;

    [Column('CITTA', [], 50)]
    FCITTA: Nullable<string>;

    [Column('PROV', [], 5)]
    FPROV: Nullable<string>;

    [Column('CAP', [], 5)]
    FCAP: Nullable<string>;

    [Column('TELEF_1', [], 20)]
    FTELEF_1: Nullable<string>;

    [Column('TELEF_2', [], 20)]
    FTELEF_2: Nullable<string>;

    [Column('DEST_DIV', [TColumnProp.Required])]
    FDEST_DIV: Boolean;

    [Column('RAG_SOC_DIV', [], 50)]
    FRAG_SOC_DIV: Nullable<string>;

    [Column('INDIRIZZO_DIV', [], 50)]
    FINDIRIZZO_DIV: Nullable<string>;

    [Column('CITTA_DIV', [], 50)]
    FCITTA_DIV: Nullable<string>;

    [Column('PROV_DIV', [], 5)]
    FPROV_DIV: Nullable<string>;

    [Column('CAP_DIV', [], 5)]
    FCAP_DIV: Nullable<string>;

    [Column('TELEF_1_DIV', [], 20)]
    FTELEF_1_DIV: Nullable<string>;

    [Column('TELEF_2_DIV', [], 20)]
    FTELEF_2_DIV: Nullable<string>;

    [Column('PART_IVA', [], 20)]
    FPART_IVA: Nullable<string>;

    [Column('COD_FISC', [], 20)]
    FCOD_FISC: Nullable<string>;

    [Column('EMAIL', [], 50)]
    FEMAIL: Nullable<string>;

    [Column('TOT_ESENTE_IVA', [], 18, 4)]
    FTOT_ESENTE_IVA: Nullable<Double>;

    [Column('TOT_IMPONIBILE', [], 18, 4)]
    FTOT_IMPONIBILE: Nullable<Double>;

    [Column('TOT_IVA', [], 18, 4)]
    FTOT_IVA: Nullable<Double>;

    [Column('TOT_OMAGGI', [], 18, 4)]
    FTOT_OMAGGI: Nullable<Double>;

    [Column('TOT_EXTRA', [], 18, 4)]
    FTOT_EXTRA: Nullable<Double>;

    [Column('TOT_DOC', [], 18, 4)]
    FTOT_DOC: Nullable<Double>;

    [Column('TOT_RICEVUTO', [], 18, 4)]
    FTOT_RICEVUTO: Nullable<Double>;

    [Column('TOT_INCASSATO', [], 18, 4)]
    FTOT_INCASSATO: Nullable<Double>;

    [Column('TOT_RESTO', [], 18, 4)]
    FTOT_RESTO: Nullable<Double>;

    [Column('STATO_DOC', [])]
    FSTATO_DOC: Nullable<Integer>;

    [Column('DATA_ORA_ASP', [])]
    FDATA_ORA_ASP: Nullable<TDateTime>;

    [Column('NOTE_ASP', [], 100)]
    FNOTE_ASP: Nullable<string>;

    [Column('CMD_PK1', [])]
    FCMD_PK1: Nullable<Integer>;

    [Column('INIZIO_INS', [])]
    FINIZIO_INS: Nullable<TDateTime>;

    [Column('FINE_INS', [])]
    FFINE_INS: Nullable<TDateTime>;

    [Column('INIZIO_ESEC', [])]
    FINIZIO_ESEC: Nullable<TDateTime>;

    [Column('FINE_ESEC', [])]
    FFINE_ESEC: Nullable<TDateTime>;

    [ManyValuedAssociation([TAssociationProp.Lazy], CascadeTypeAllRemoveOrphan, 'FPK_1')]

    Function Get_ORD_RISTO_R: TList<TORD_RISTO_R>;
    Constructor Create; Overload;
    Destructor Destroy; Override;

    property PK_1: Integer read FPK_1 write FPK_1;
    property CAUSALE: Nullable<string> read FCAUSALE write FCAUSALE;
    property TIPO_DOC: Nullable<string> read FTIPO_DOC write FTIPO_DOC;
    property VEN_POS: Boolean read FVEN_POS write FVEN_POS;
    property DATA_DOC: Nullable<TDateTime> read FDATA_DOC write FDATA_DOC;
    property NUM_DOC: Nullable<string> read FNUM_DOC write FNUM_DOC;
    property COD_PC: Nullable<string> read FCOD_PC write FCOD_PC;
    property COD_OPER: Nullable<string> read FCOD_OPER write FCOD_OPER;
    property TIPO_SOGG: Nullable<string> read FTIPO_SOGG write FTIPO_SOGG;
    property COD_CLIFOR: Nullable<string> read FCOD_CLIFOR write FCOD_CLIFOR;
    property COD_CLI_GFE: Nullable<string> read FCOD_CLI_GFE write FCOD_CLI_GFE;
    property RAG_SOC: Nullable<string> read FRAG_SOC write FRAG_SOC;
    property INDIRIZZO: Nullable<string> read FINDIRIZZO write FINDIRIZZO;
    property CITTA: Nullable<string> read FCITTA write FCITTA;
    property PROV: Nullable<string> read FPROV write FPROV;
    property CAP: Nullable<string> read FCAP write FCAP;
    property TELEF_1: Nullable<string> read FTELEF_1 write FTELEF_1;
    property TELEF_2: Nullable<string> read FTELEF_2 write FTELEF_2;
    property DEST_DIV: Boolean read FDEST_DIV write FDEST_DIV;
    property RAG_SOC_DIV: Nullable<string> read FRAG_SOC_DIV write FRAG_SOC_DIV;
    property INDIRIZZO_DIV: Nullable<string> read FINDIRIZZO_DIV write FINDIRIZZO_DIV;
    property CITTA_DIV: Nullable<string> read FCITTA_DIV write FCITTA_DIV;
    property PROV_DIV: Nullable<string> read FPROV_DIV write FPROV_DIV;
    property CAP_DIV: Nullable<string> read FCAP_DIV write FCAP_DIV;
    property TELEF_1_DIV: Nullable<string> read FTELEF_1_DIV write FTELEF_1_DIV;
    property TELEF_2_DIV: Nullable<string> read FTELEF_2_DIV write FTELEF_2_DIV;
    property PART_IVA: Nullable<string> read FPART_IVA write FPART_IVA;
    property COD_FISC: Nullable<string> read FCOD_FISC write FCOD_FISC;
    property EMAIL: Nullable<string> read FEMAIL write FEMAIL;
    property TOT_ESENTE_IVA: Nullable<Double> read FTOT_ESENTE_IVA write FTOT_ESENTE_IVA;
    property TOT_IMPONIBILE: Nullable<Double> read FTOT_IMPONIBILE write FTOT_IMPONIBILE;
    property TOT_IVA: Nullable<Double> read FTOT_IVA write FTOT_IVA;
    property TOT_OMAGGI: Nullable<Double> read FTOT_OMAGGI write FTOT_OMAGGI;
    property TOT_EXTRA: Nullable<Double> read FTOT_EXTRA write FTOT_EXTRA;
    property TOT_DOC: Nullable<Double> read FTOT_DOC write FTOT_DOC;
    property TOT_RICEVUTO: Nullable<Double> read FTOT_RICEVUTO write FTOT_RICEVUTO;
    property TOT_INCASSATO: Nullable<Double> read FTOT_INCASSATO write FTOT_INCASSATO;
    property TOT_RESTO: Nullable<Double> read FTOT_RESTO write FTOT_RESTO;
    property STATO_DOC: Nullable<Integer> read FSTATO_DOC write FSTATO_DOC;
    property DATA_ORA_ASP: Nullable<TDateTime> read FDATA_ORA_ASP write FDATA_ORA_ASP;
    property NOTE_ASP: Nullable<string> read FNOTE_ASP write FNOTE_ASP;
    property CMD_PK1: Nullable<Integer> read FCMD_PK1 write FCMD_PK1;
    property INIZIO_INS: Nullable<TDateTime> read FINIZIO_INS write FINIZIO_INS;
    property FINE_INS: Nullable<TDateTime> read FFINE_INS write FFINE_INS;
    property INIZIO_ESEC: Nullable<TDateTime> read FINIZIO_ESEC write FINIZIO_ESEC;
    property FINE_ESEC: Nullable<TDateTime> read FFINE_ESEC write FFINE_ESEC;

  [Id('FPK_1', TIdGenerator.None)]
  [Id('FPK_2', TIdGenerator.None)]
  TORD_RISTO_R = class
    [Column('PK_2', [TColumnProp.Required])]
    FPK_2: Integer;

    [Column('POS_RIGO', [])]
    FPOS_RIGO: Nullable<Integer>;

    [Column('TIPO_RIGO', [], 3)]
    FTIPO_RIGO: Nullable<string>;

    [Column('ART_PK1', [])]
    FART_PK1: Nullable<Integer>;

    [Column('DATICONT_PK2', [])]
    FDATICONT_PK2: Nullable<Integer>;

    [Column('TIPO_ART', [], 3)]
    FTIPO_ART: Nullable<string>;

    [Column('DESC_ART', [], 100)]
    FDESC_ART: Nullable<string>;

    [Column('DESC_BREVE', [], 100)]
    FDESC_BREVE: Nullable<string>;

    [Column('COD_SET', [], 5)]
    FCOD_SET: Nullable<string>;

    [Column('COD_GRP', [], 10)]
    FCOD_GRP: Nullable<string>;

    [Column('COD_UM', [], 5)]
    FCOD_UM: Nullable<string>;

    [Column('VEND_A_FRAZ', [TColumnProp.Required])]
    FVEND_A_FRAZ: Boolean;

    [Column('PZ_PER_CF', [])]
    FPZ_PER_CF: Nullable<Integer>;

    [Column('QUANTITA', [], 18, 4)]
    FQUANTITA: Nullable<Double>;

    [Column('PREZZO', [], 18, 4)]
    FPREZZO: Nullable<Double>;

    [Column('PREZZO_IVATO', [TColumnProp.Required])]
    FPREZZO_IVATO: Boolean;

    [Column('TOT_IMPORTO', [], 18, 4)]
    FTOT_IMPORTO: Nullable<Double>;

    [Column('TOT_IMP_NET', [], 18, 4)]
    FTOT_IMP_NET: Nullable<Double>;

    [Column('TOT_IVA', [], 18, 4)]
    FTOT_IVA: Nullable<Double>;

    [Column('TOT_RIGO', [], 18, 4)]
    FTOT_RIGO: Nullable<Double>;

    [Column('COD_STP_1', [])]
    FCOD_STP_1: Nullable<Integer>;

    [Column('COD_STP_2', [])]
    FCOD_STP_2: Nullable<Integer>;

    [Column('COD_STP_3', [])]
    FCOD_STP_3: Nullable<Integer>;

    [Column('MEZZA_PORZ', [TColumnProp.Required])]
    FMEZZA_PORZ: Boolean;

    [Column('VALUTA_QTA_VAR', [TColumnProp.Required])]
    FVALUTA_QTA_VAR: Boolean;

    [Column('APPLICA_RID_VAR', [TColumnProp.Required])]
    FAPPLICA_RID_VAR: Boolean;

    [Column('NUM_VAR_VIV', [])]
    FNUM_VAR_VIV: Nullable<Integer>;

    [Column('PK2_RIGO_ART', [])]
    FPK2_RIGO_ART: Nullable<Integer>;

    [Association([TAssociationProp.Lazy], CascadeTypeAllButRemove - [TCascadeType.Flush])]
    [JoinColumn('PK_1', [TColumnProp.Required])]

    property PK_2: Integer read FPK_2 write FPK_2;
    property POS_RIGO: Nullable<Integer> read FPOS_RIGO write FPOS_RIGO;
    property TIPO_RIGO: Nullable<string> read FTIPO_RIGO write FTIPO_RIGO;
    property ART_PK1: Nullable<Integer> read FART_PK1 write FART_PK1;
    property DATICONT_PK2: Nullable<Integer> read FDATICONT_PK2 write FDATICONT_PK2;
    property TIPO_ART: Nullable<string> read FTIPO_ART write FTIPO_ART;
    property DESC_ART: Nullable<string> read FDESC_ART write FDESC_ART;
    property DESC_BREVE: Nullable<string> read FDESC_BREVE write FDESC_BREVE;
    property COD_SET: Nullable<string> read FCOD_SET write FCOD_SET;
    property COD_GRP: Nullable<string> read FCOD_GRP write FCOD_GRP;
    property COD_UM: Nullable<string> read FCOD_UM write FCOD_UM;
    property VEND_A_FRAZ: Boolean read FVEND_A_FRAZ write FVEND_A_FRAZ;
    property PZ_PER_CF: Nullable<Integer> read FPZ_PER_CF write FPZ_PER_CF;
    property QUANTITA: Nullable<Double> read FQUANTITA write FQUANTITA;
    property PREZZO: Nullable<Double> read FPREZZO write FPREZZO;
    property PREZZO_IVATO: Boolean read FPREZZO_IVATO write FPREZZO_IVATO;
    property TOT_IMPORTO: Nullable<Double> read FTOT_IMPORTO write FTOT_IMPORTO;
    property TOT_IMP_NET: Nullable<Double> read FTOT_IMP_NET write FTOT_IMP_NET;
    property TOT_IVA: Nullable<Double> read FTOT_IVA write FTOT_IVA;
    property TOT_RIGO: Nullable<Double> read FTOT_RIGO write FTOT_RIGO;
    property COD_STP_1: Nullable<Integer> read FCOD_STP_1 write FCOD_STP_1;
    property COD_STP_2: Nullable<Integer> read FCOD_STP_2 write FCOD_STP_2;
    property COD_STP_3: Nullable<Integer> read FCOD_STP_3 write FCOD_STP_3;
    property MEZZA_PORZ: Boolean read FMEZZA_PORZ write FMEZZA_PORZ;
    property VALUTA_QTA_VAR: Boolean read FVALUTA_QTA_VAR write FVALUTA_QTA_VAR;
    property NUM_VAR_VIV: Nullable<Integer> read FNUM_VAR_VIV write FNUM_VAR_VIV;
    property PK2_RIGO_ART: Nullable<Integer> read FPK2_RIGO_ART write FPK2_RIGO_ART;



constructor TORD_RISTO_T.Create();
// -------------------------------
// -------------------------------
destructor TORD_RISTO_T.Destroy();

The error indicates that you have a circular reference in the underlying object in the dataset.
Given that your two classes reference each other, you probably have that circular reference.
I noticed your FPK_1 is not using Proxy<T>, any reason for that? Try to always keep it lazy-loaded, it helps.

Can you give me the corrections ?

Here is how you should use lazy loading: Mapping | TMS Aurelius documentation

you write : noticed your FPK_1 is not using Proxy<T> , but in detail table ? i don't known how set it ... i read manuals but i see all fine ... sure i'm wrong something !

googling i found this :

JavaScript structures that include circular references can't be serialized with a"plain" JSON.stringify. Example:

a = { name: 'Groucho' };
b = { name: 'Harpo', sibling: a };
a.sibling = b;

Doing a JSON.stringify(a) will throw an error: TypeError: Converting circular structure to JSON

but i don't know how apply corrections in M/D tables of my project ...

As the manual describes, declare it as a proxy:

    [Association([TAssociationProp.Lazy], CascadeTypeAllButRemove - [TCascadeType.Flush])]
    [JoinColumn('PK_1', [TColumnProp.Required])]
    FPK_1: Proxy<TORD_RISTO_T>;

And create the getters and setters for the public property:

property PK_1: TORD_RISTO_T read GetPK_1 write SetPK_1;