It's probably an Aurelius thing. I'm beginning to think that if I were to use direct DB access with SQL in these services, it would not have been an issue...
But remarkably, it sometimes works.
PS: It took me an hour yesterday to write code in Aurelius to just do a simple "count(*)" - it really should be improved somehow, it's waaaaay too convoluted as it is.
And another issue I'm running into is that if the server is restarted, the client almost certainly starts throwing exceptions.
PPS: And it was a surprise that TXDataClient was not a TComponent, why is that? It just makes it harder to use.
You should not call xxx.Free if you save it using the manager. When you save, the manager takes control of the object lifetime and will destroy it eventually, leading to a double destroy. That's the cause of your error.
Side note: properly format the code, wrapping the text using triple backslashes (```) or select the text and click the "code" button to format it:
CountResult := ServerContainer.AureliusManager.ObjManager.Find<Tyyy>.Where(Linq['AAA'] = Aaaa).Select(TProjections.Sql<Int64>('count(*)')).UniqueValue;
if Assigned(CountResult) then
try
result := CountResult.Values[0];
finally
CountResult.Free;
end;
It's important to note that TCriteriaResult objects are not managed by the TObjectManager , so the retrieved objects must be destroyed. When using ListValues method to retrieve the results, the returned list is a TObjectList object that already has its OwnsObjects property set to true. So destroyed the list should be enough. When using UniqueValue or Open methods, you must be sure to destroy the TCriteriaResult objects.