How Load, Proxy<T>.Key

Hi
  How to Load TEntity.JobId.Id without load TJob:
  [...]
  TEntity = class
  private
    FId: Int64;
    FName: string;
   
    [Association([TAssociationProp.Lazy], CascadeTypeAll - [TCascadeType.Remove])]
    [JoinColumn('JobId', [], 'Id')]
    FJobId: Proxy<TJob>;
    ... 
  public
    ...
  end;

  [...]
  TJob = class
  private
    FId: Int64;
    FDescription: string;
  public
    ...
  end;

I'm trying to test this new feature, but i can make this work:
  "New: Proxy<T>.Key property. Allows you to get the database value of
    foreign key without needing to load the proxy object."

What have you tried, exactly? That's pretty much it: retrieve the id by reading the Key property of the proxy:


Id := FJobid.Key;

sorry but something is missing
do you mean:
...
var
  fEntity: TEntity;
  Id: Integer;
begin
  fEntity := Manager.find<TEntity>(1);
  Id := fEntity.JobId.Key;
end;

if so:
[dcc32 Error] DB.Entity.pas(838): E2003 Undeclared identifier: 'key'

Thanks

Well, I didn't see your full class, but I guess fEntity.JobId is of type TJob, not Proxy<TJob>, isn't it? If yes, then of course Key property will not be available.

It's the Proxy<TJob> that has a Key property, not your entity. You can simply create a property JobIdKey and implement the getter returning the Key value from the proxy type.

Hi,
  "...but I guess fEntity.JobId is of type TJob...", no, has you can see in TEntity,
    [Association([TAssociationProp.Lazy], CascadeTypeAll - [TCascadeType.Remove])]
    [JoinColumn('JobId', [], 'Id')]
    FJobId: Proxy<TJob>;

thanks

 

That FJobId, not JobId.


Hi, sorry Wagner but i just can't understand.
FJobId is Private, and should access Public properties
...
public
    property JobId: TJob read GetJobId write SetJobId;
...

One more thing, Schema is generate with DataModeler

Thanks

That's why I said you should do something like




property JobIdKey: Integer read GetJobIdKey;
...
function Entity.GetJobIdKey: Integer;
begin
  Result := FJobId.Key;
end;

Hi, Wagner :)
  But after generate Schema with the Data Modeler, i have to add 'GetJobIdKey' to class TEntity?
Something like a class Helper? what's your idea?
 Thanks

You can use a class helper, edit the unit manually, or use customization scripts to add extra code to the generated unit.

Hi, Wagner
  For now I will choose "Class Helper" but "Customization scripts" looks like a good solution.
  "Customization scripts" Feature has a good potential, maybe i use in future, great work.

Many Thanks Wagner