Refresh Lists without generics

regarding TObjectManager.Refresh ignores cascade-Refresh - #3

is it possible to Refresh a List not using generics?

I would like to provide a method that will scan associations and refresh lists with a single statement, like you described it here:

Invoices := Manage.Find<T>.Refreshing.List;
for hAssoc in Explorer.GetAssociations(aEntity.ClassType, True, True) do
  begin
      hVal := hAssoc.Optimization.Wrapper.GetValue(aEntity);
      if hVal.IsEmpty then
        Continue;

      if hAssoc.Kind = TAssociationKind.ManyValued then
      begin
        Assert(Explorer.IsObjectList(hVal.AsObject.ClassType));
        hObjList := Explorer.AsObjectList(hVal.AsObject);

        for i := 0 to Pred(hObjList.Count) do
          if IsAttached(hObjList.Item(i)) and HasChanges(hObjList.Item(i)) then
            Refresh(hObjList.Item(i));
      end
      else
      begin
        Assert(hVal.IsType<TEntity>);
        hEntity := hVal.AsType<TEntity>;
        if IsAttached(hObjList.Item(i)) and HasChanges(hObjList.Item(i)) then
          Refresh(hEntity);
      end;
  end;

so maybe you could provide a method refreshing all Items of an IObjectList, only triggering some fetches, not single fetches at all...

current version of this loop looks like that:

var
  hAssoc: TAssociation;
  hVal: TValue;
  hEntity: TEntity;
  hObjList: IObjectList;
  i: Integer;
...
  for hAssoc in Explorer.GetAssociations(aEntity.ClassType, True, True) do
  begin
    if not hAssoc.Lazy then // Associations, that are not Lazy (not proxy), will be refreshed automatically // https://support.tmssoftware.com/t/lazy-loading-and-refreshing/7953
      Continue;

    // we have to Refresh loaded lazy Assocs only...
//    if not Explorer.IsProxyLoaded(aEntity, hAssoc.Optimization) then // returns false, although the property has been accessed... see https://support.tmssoftware.com/t/explorer-isproxyloaded-returns-false-for-loaded-proxy-lists/21767
//      Continue;

    hVal := hAssoc.Optimization.Wrapper.GetValue(aEntity);
    if hVal.IsEmpty then
      Continue;

    if hAssoc.Kind = TAssociationKind.ManyValued then
    begin
      Assert(Explorer.IsObjectList(hVal.AsObject.ClassType));
      hObjList := Explorer.AsObjectList(hVal.AsObject);

      for i := 0 to Pred(hObjList.Count) do
        if IsAttached(hObjList.Item(i)) and HasChanges(hObjList.Item(i)) then
          Refresh(hObjList.Item(i));
    end
    else
    begin
      Assert(hVal.IsType<TEntity>);
      hEntity := hVal.AsType<TEntity>;
      if IsAttached(hEntity) and HasChanges(hEntity) then
        Refresh(hEntity);
    end;
  end;

TEntity is my base AbstractEntity providing FId for all inherited entities...

Thanks for contribution.
What do you mean by "refresh a list not using generics"?

this would fetch all Entities at once.
My Solution will fire several queries, what is finally a performance-issue...

But I do not know, how to refresh these entities with a single statement not knowing the final class at this point...

For items in a many-valued association list, you should refresh each item individually.

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