Wagner
I would like your opinion on the best way to buy if two objects are equal,
being equal do not send a put to the server and inform the user that the object has not been changed;
Problem 1:
I tried to use the class TDataSnapJsonSerializer (Aurelius.Json.DataSnap), but I did not succeed
for more complex entities (with associations), since fields are returned out of order at each serialization.
Ex.:
loEntidadeComplexa1 := FClient.Get<TEntidadeComplexa>(10);
loJson1 := loEntidadeComplexa1.ToJsonString;
loEntidadeComplexa2 := FClient.Get<TEntidadeComplexa>(10);
loJson2 := loEntidadeComplexa2.ToJsonString;
if loJson1 <> loJson2 then
FClient.Put(loEntidadeComplexa2)
else
Showmessage('No data was changed');
...
Serialization result loJson1:
{
"$type": "App.Modelo.Entidade.TEntidadeComplexa",
"$id": 1,
"FNome": "FAZENDA TR\u00CAS PONTAS ALTERADO",
"FAreaCultura": 38000,
"FQuantidadeNascente": 3,
"FCooperado": {
"$proxy": "single",
"key": null,
"class": "",
"member": ""
},
"FCulturas": {
"$proxy": "list",
"key": null,
"class": "",
"member": ""
}, ...
Serialization result loJson2:
{
"$type": "App.Modelo.Entidade.TEntidadeComplexa",
"$id": 1,
"FValidade": "2020-02-10",
"FObservacao": null,
"FImagemMapa": {
"$lazyblob": true,
"key": null,
"class": "",
"member": ""
},
"FCooperado": {
"$proxy": "single",
"key": null,
"class": "",
"member": ""
}, ...
Problem 2:
Accessing a property that references another entity also changes the final json.
[Entity]
[Table('MUNICIPIO')]
[Sequence('SEQ_MUNICIPIO')]
[Id('FID', TIdGenerator.IdentityOrSequence)]
TMunicipio = class
strict private
[Column('ID')]
FID: Integer;
[Column('NOME', [TColumnProp.Unique, TColumnProp.Required], 40)]
FNome: string;
[Association([TAssociationProp.Lazy], CascadeTypeAllButRemove)]
[ForeignKey('FK_MUNICIPIO_UF')]
[JoinColumn('ID_UNIDADE_FEDERATIVA', [TColumnProp.Required])]
FUnidadeFederativa: Proxy<TUnidadeFederativa>;
protected ...
loMunicipio1 := FClient.Get<TMunicipio>(12);
loJson1 := loMunicipio1.ToJsonString;
loMunicipio2 := FClient.Get<TMunicipio>(12);
UF := loMunicipio2.UnidadeFederativa.Nome;
loJson2 := loMunicipio2.ToJsonString;
...
Serialization result loJson1:
{
"$type": "App.Modelo.Entidade.TMunicipio",
"$id": 1,
"FID": 12,
"FNome": "TR\u00CAS PONTAS",
"FUnidadeFederativa": {
"$proxy": "single",
"key": null,
"class": "",
"member": ""
}
}
Serialization result loJson2:
{
"$type": "App.Modelo.Entidade.TMunicipio",
"$id": 1,
"FID": 12,
"FNome": "TR\u00CAS PONTAS",
"FUnidadeFederativa": {
"$type": "App.Modelo.Entidade.TUnidadeFederativa",
"$id": 2,
"FID": 11,
"FNome": "MINAS GERAIS",
"FSigla": "MG",
"FCodigoIBGE": 31,
"FPais": {
"$type": "App.Modelo.Entidade.TPais",
"$id": 3,
"FID": 27,
"FCodigo": 55,
"FNomePtBr": "BRASIL",
"FNomeEn": "BRAZIL",
"FSigla2": "BR",
"FSigla3": "BRA"
}
}
}
I think using Json is not the best option, you agree?
What is the best way to do this comparison? Does Aurelius have any features that make this easy?
Thank you