Issue marked as solved too soon

I saw a good looking reply from Wagner for this topic:

https://support.tmssoftware.com/t/question-about-how-to-return-classtype-or-classref/23258/3

And so I marked it solved. Then tried to use the suggested code. It has returned the error:

E2531 Method 'UniqueResult' requires explicit type argument(s)

Here is my code:

function TKKFUPhoneService.DeleteRecord(aID: Integer;
aTableName: String): Boolean;

var
aEntity: TObject;
aClass: TPersistentClass;
begin
Result := false;
aClass:= GetClass('T' + aTableName);
if aClass <> Nil then
aEntity:= Manager.Find(aClass).WHERE(TLinq.Eq('ID', aID)).UniqueResult;
if Assigned(aEntity) then
begin
Manager.Remove(aEntity);
Result:= true;
end;

My intention is to be able to dynamically assign the class of the Aurelius Entity to allow "Remove" to be called against any Entity from a single method call.

Since you used the non-generic version of Find method, Delphi can't tell what is the result type of UniqueResult, so you must tell the class you want. Just use TObject:

aEntity:= Manager.Find(aClass)
  .WHERE(TLinq.Eq('ID', aID)).UniqueResult<TObject>;

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