Hello,
I have a problem with an object
return by a query. The foreign keys are not lazy-loaded, I even tried to
force the fetch mode to "Eager", but I get a resulting object that
doesn't contain the sub-tables i need.
part of the model
[Entity]
[Table('CARTE_CLIENT_CATEGORIE')]
[Sequence('GNNUM_CARTE_CLIENT_CATEGORIE')]
[Id('FCODECHRONO', TIdGenerator.IdentityOrSequence)]
TCarteClientCategorie = class
private
[Column('CODECHRONO', [TColumnProp.Required])]
FCODECHRONO: Integer;
[Column('IDCARTE', [])]
FIDCARTE: Nullable<Integer>;
[Column('ORDRE', [])]
FORDRE: Nullable<Integer>;
[Column('LIBELLE', [], 40)]
FLIBELLE: Nullable<string>;
[Column('IMAGE', [])]
FIMAGE: Nullable<TBlob>;
[ManyValuedAssociation([], [TCascadeType.SaveUpdate, TCascadeType.Merge], 'FIDCATEGORIE')]
FCarteClientProduits : TList<TCarteClientProduit>;
public
constructor Create;
destructor Destroy; override;
property CODECHRONO: Integer read FCODECHRONO write FCODECHRONO;
property IDCARTE: Nullable<Integer> read FIDCARTE write FIDCARTE;
property ORDRE: Nullable<Integer> read FORDRE write FORDRE;
property LIBELLE: Nullable<string> read FLIBELLE write FLIBELLE;
property IMAGE: Nullable<TBlob> read FIMAGE write FIMAGE;
property CARTECLIENTPRODUITS: TList<TCarteClientProduit> read FCarteClientProduits;
end;
[Entity]
[Table('CARTE_CLIENT_PRODUITS')]
[Sequence('GNNUM_CARTE_CLIENT_PRODUITS')]
[Id('FCODECHRONO', TIdGenerator.IdentityOrSequence)]
TCarteClientProduit = class
private
[Column('CODECHRONO', [TColumnProp.Required])]
FCODECHRONO: Integer;
[Association([], CascadeTypeAllButRemove)]
[JoinColumn('IDCATEGORIE', [], 'CODECHRONO')]
FIDCATEGORIE: TCarteClientCategorie;
[Column('IDPRODUIT', [])]
FIDPRODUIT: Nullable<Integer>;
[Column('ORDRE', [])]
FORDRE: Nullable<Integer>;
public
property CODECHRONO: Integer read FCODECHRONO write FCODECHRONO;
property IDCATEGORIE: TCarteClientCategorie read FIDCATEGORIE write FIDCATEGORIE;
property IDPRODUIT: Nullable<Integer> read FIDPRODUIT write FIDPRODUIT;
property ORDRE: Nullable<Integer> read FORDRE write FORDRE;
end;
The query
function TDemandesClientsService.getCarte(id: Integer): TObjectList<TCarteClientCategorie>;
var
objectManager : TObjectManager;
begin
objectManager := TXDataOperationContext.Current.GetManager;
Result := objectManager.Find<TCarteClientCategorie>
.Where(Linq[Dic.CarteClientCategorie.IDCARTE.PropName] = id)
.CreateAlias('CARTECLIENTPRODUITS', 'p', TFetchMode.Eager)
.AddOrder(TOrder.Asc(Dic.CarteClientCategorie.ORDRE.PropName))
.AddOrder(TOrder.Asc('p.ORDRE'))
.List;
end;
The resulting JS object received by Web Core' javascript
Categories: (19) [
0: {
"$id": 1
"@xdata.type": "XData.Default.CarteClientCategorie"
CODECHRONO: 1
"CarteClientProduits@xdata.proxy": "CarteClientCategorie(1)/CarteClientProduits"
IDCARTE: 1
IMAGE: null
LIBELLE: "Lib1"
ORDRE: 1
}
1: {
"$ref": 1
}
2: {
"$ref": 1
}
3: {
"$ref": 1
}
4: {
"$id": 2
"@xdata.type": "XData.Default.CarteClientCategorie"
CODECHRONO: 2
CarteClientProduits: []
IDCARTE: 1
IMAGE: null
LIBELLE: "Lib2"
ORDRE: 2 }
5: {
"$id": 3
"@xdata.type": "XData.Default.CarteClientCategorie"
CODECHRONO: 33
"CarteClientProduits@xdata.proxy": "CarteClientCategorie(33)/CarteClientProduits"
IDCARTE: 1
IMAGE: null
LIBELLE: "Lib3"
ORDRE: 3
}
etc...
]
Those
empty nodes correspond to child elements but i don't understand why
they are empty, and why they are at the root of the array
1: {
"$ref": 1
}
When
there are no child element, I get an empty object, that the only point
OK, but when there must be entries I get a proxy link
"CarteClientProduits@xdata.proxy": "CarteClientCategorie(1)/CarteClientProduits"
I may do things wrong somewhere or simply don't understand what I get.
Thanks in advance for your help.