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...
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...