How is the class loaded with TFetchMode.Eager

Hi,

I Have A Class TCustomer with property CustomerToAddress

type
  [Entity]
  [Table('CUSTOMERS')]
  TCustomer = class (TBaseWithID)
  private
    [Column('FIRSTNAME')]
    FFirstName: String;
    [Column('NAME')]
    FName: String;

    [ManyValuedAssociation([TAssociationProp.Lazy], CascadeTypeAll)]
    [ForeignJoinColumn('CUSTOMERID', [TColumnProp.Required])]
    FCustomerToAddress: Proxy<TList<TCustomerToAddress>>;

    [ManyValuedAssociation([TAssociationProp.Lazy], CascadeTypeAll)]
    [ForeignJoinColumn('CUSTOMERID', [TColumnProp.Required])]
    FCustomerToAddress1: Proxy<TList<TCustomerToAddress1>>;

    [ManyValuedAssociation([TAssociationProp.Lazy], CascadeTypeAll)]
    [ForeignJoinColumn('CUSTOMERID', [TColumnProp.Required])]
    FCustomerToAddress3: Proxy<TList<TCustomerToAddress3>>;


    procedure SetFirstName(const Value: String);
    procedure SetName(const Value: String);


    function GetCustomerToAddress: TList<TCustomerToAddress>;
    function GetCustomerToAddress1: TList<TCustomerToAddress1>;
    function GetCustomerToAddress3: TList<TCustomerToAddress3>;

  public

    property FirstName: String read FFirstName write SetFirstName;
    property Name: String read FName write SetName;

    property CustomerToAddress: TList<TCustomerToAddress> read GetCustomerToAddress;
    property CustomerToAddress1: TList<TCustomerToAddress1> read GetCustomerToAddress1;
    property CustomerToAddress3: TList<TCustomerToAddress3> read GetCustomerToAddress3;
  end;


I want that the associactions CustomerToAddress is loaded, so I use this code:

  oCustomers:= Mng.Find<TCustomer>
                  .CreateAlias('CustomerToAddress', 'cta', TFetchMode.Eager)
                  .Where(Linq.Like('Name', 'MARC'))
                  .List;

But when I convert it to a Json the CustomerToAddress is not loaded.

Json:

'[{"$type":"Entities.Customer.TCustomer","$id":1,"FID":1772,"FFirstName":"","FName":"Marc",
"FCustomerToAddress":{"$proxy":"list","key":1772,"class":"TCustomer","member":"FCustomerToAddress"},
"FCustomerToAddress1":{"$proxy":"list","key":1772,"class":"TCustomer","member":"FCustomerToAddress1"},
"FCustomerToAddress3":{"$proxy":"list","key":1772,"class":"TCustomer","member":"FCustomerToAddress3"}}]'


I think that the CustomerToAddress is not loaded, because when I to oCustomers.First.CustomerToAddress and then an conversion to Json then I get


'[{"$type":"Entities.Customer.TCustomer","$id":1,"FID":1772,"FFirstName":"","FName":"Marc",
"FCustomerToAddress":[{"$type":"Entities.CustomerToAddress.TCustomerToAddress1","$id":2,"FCustomerID":1772,"FAddressID":2228,"FAddressTypeID":1,"FAddress":{"$proxy":"single","key":2228,"class":"TCustomerToAddress","member":"FAddress"}}],
"FCustomerToAddress1":{"$proxy":"list","key":1772,"class":"TCustomer","member":"FCustomerToAddress1"},
"FCustomerToAddress3":{"$proxy":"list","key":1772,"class":"TCustomer","member":"FCustomerToAddress3"}}]'

Any Idee?
I gone a set the logger to see if the sqlquery is correct.






The SQL script is OK.

SQL SCRIP:

SELECT A.ID AS A_ID, A.FIRSTNAME AS A_FIRSTNAME, A.NAME AS A_NAME
FROM CUSTOMERS A
  LEFT JOIN CUSTOMERS2ADDRESSES B ON (B.CUSTOMERID = A.ID)
WHERE  A.NAME LIKE :p_0
p_0 = "MARC" (ftString)


but I want that CustomerToAddress is loaded before I call Customer.CustomerToAddress.
Is there something with .List... 

TFetchMode.Eager only affects single-value associations. Many-valued associations (lists) are not affected by it.

Hello,

Is there something else (function in Aurelius) that can load the many-valued associations like the TFetchMode.Eager?


You can simply iterate through the list and call the property directly to force it to be loaded. If you are using XData, client users can simply choose to expand it using $expand=CustomerToAddress query option.

Thanks,

in meantime I 've make some code like:

function TTransfer.List<T>(aManager: TObjectManager): TList<T>;
var
  oCriteria: TCriteria<T>;
  oFilter: TCustomCriterion;
  oItem: T;
  oFetchEagerAlias: TFetchEagerAlias;
  oExpression: TCustomCriterion;
begin
  oCriteria := aManager.Find<T>;

  for oExpression in self.CustomCriterionList do
  begin
    oCriteria.Add(oExpression); // does not work --> no Value
  end;

  Result:= oCriteria.List;

  If self.HaveFetchEagerAlias
  then begin
    for oItem in Result do
    begin
      for oFetchEagerAlias in self.FetchEagerAliasList do
      begin
        TRttiUtils.GetProperty(oItem, oFetchEagerAlias.AssociationPath);
      end;
    end;
  end;
end;