My Entity will be deleted

I have a problem with the result of a query.

The code is in a XData service function

I call Login with Name/Password
In my service function I call CheckUser(Username,Password) and want to get the User.
The FUser Object is in the class.

I find the User. Everything ok. In the debugger, I cann see all. In this function I can use the FUser.
But if I get out of the function CheckUser and go back to "Login_v1" the FUser is "inaccessible".
Will the List be deleted? (the TUserlist : TObejctList<TUser>)

Please look at the code.
I call the function at line ##########################
The reading process is bold

Thank you.



unit Auth.func.Impl;
interface
uses
  ( ... )


type
  [ServiceImplementation]
  TAuthFunc = class(TInterfacedObject, IsngFunc, IAuthFunc)


  strict private  // Interface IAuthFunc
    function Login               ( const Param: TJSONObject)  : TJSONObject;


  private
    FUser : TUser;  // User aus Datenbank
    function Login_v1            ( const AsngPara: TsngParameter) : TJSONObject;
    function CheckUser           ( const Username, Password: string): integer;
  end;


implementation


uses
  ( ... )


function TAuthFunc.Login( const Param: TJSONObject)  : TJSONObject;
begin
  ( ... )
      Result := Login_v1( sngPara)
  ( ... )
end;


function TAuthFunc.Login_v1( const AsngPara: TsngParameter) : TJSONObject;
var
  JWT       : TJWT;
  LUsername : string;
  LPassword : string;
  LResult   : TsngResult;
  res       : integer;
begin
  ( ... )
//###########################################################
  res := CheckUser( LUsername, LPassword);
//###########################################################


  if res <> smc_ok then begin
    LResult := TsngResult.Create( res, local_location_prefix+'Login_v1');
    Result := LResult.toJSONObject;
    LResult.Free;
    exit;
  end;


  if not assigned( FUser) then
    raise Exception.Create(local_location_prefix+'Login_v1: interner Fehler: User nicht initialisiert.');


  try
    JWT := TJWT.Create;
    try
      JWT.Claims.Issuer     := 'SOPHA Server App';
      JWT.Claims.Subject    := FUser.Name;


  ( ... )


  finally
    JWT.Free;
  end;
end;




function TAuthFunc.CheckUser(const Username, Password: string): integer;
var
  LSession : IDBSession;
  LUserEncoded     : string;       // der verschlüsselte Username
  LPasswordEncoded : string;       // das verschlüsselte Passwort
  LUserlist : TObjectList<TUser>;  // Userliste aus Datenbank
begin


  LSession := TDBSession.Create( TdmDatabaseAuth(dmDatabase).DBConnection);


    LUserEncoded := Username;

    LUserlist := LSession.objManager.Find<TUser>
                   .Where(Linq['Name'] = LUserEncoded)
                   .List;


    if LUserlist.Count <> 1 then begin
      DoLog( loaWarning, 'User nicht gefunden!');
      Result := smcAuth_UserNotExists;
      exit;
    end;
    FUser := LUserlist[0];  

    LPasswordEncoded := HashKey( Password);


    if FUser.Password <> LPasswordEncoded then begin
      Result := smcAuth_WrongPassword;
      exit;
    end;
  end;


  result := smc_Ok;
end;




initialization
  RegisterServiceType(TAuthFunc);


end.

If I change the kind of get the User to



    FUser := LSession.objManager.Find<TUser>
                   .Where((Linq['Name'] = LUserEncoded) or (Linq['Shortname'] = LUserEncoded))
                   .UniqueResult;

nothing is changing.
The FUser Object is "inaccessable" after I leave the function

All objects retrieved by the manager are destroyed when the manager is destroyed. From your code the  object implementing LSession is destroyed when the function is over. I'm guessing such object also destroys the manager it contains, so in turn it will also destroy the FUser it retrieved.

Yes. That's it.

I have read the last sentence in the doc

http://www.tmssoftware.biz/business/aurelius/doc/web/retrieving_an_object_list.html
that I must destroy the list.

But I didn't consider that if the manager is destroyed, this won't apply.

Now it works fine.