How to map one-to-one association

You should always map a one-to-many, and then you can add wrappers to make your object behave as 1-1 at OOP-level:



TPerson = class
private
  [ManyValuedAssociation([TAssociationProp.Lazy], CascadeTypeAll)]
  FAddresses: Proxy<TList<TAddress>>;
public
  property Address: TAddress read GetAddress write SetAddress;
end;


function TPerson.GetAddress: TAddress;
begin
  if FAddresses.Value.Count > 0 then
    Result := FAddresses.Value[0]
  else
    Result := nil;
end;


procedure TPerson.SetAddress(Value: TAddress);
begin
  if FAddresses.Value.Count = 0 then
    FAddresses.Add(Value)
  else
    FAddresses[0] := Value;
end;

  

Wagner R. Landgraf2019-01-28 12:18:17