Hi,
How to EagerLoad TPerson5.PhotoId?
Manager.Find<TPerson1>.CreateAlias(TPerson5.PhotoId.AssociationName,
TPerson5.PhotoId.AssociationName, TFetchMode.Eager).List; // someting like this
TPerson1 = class
private
FId: Int64;
FName: string;
end;
TPerson2 = class (TPerson1)
private
FId: Int64;
end;
TPerson3 = class (TPerson2)
private
FId: Int64;
end;
TPerson4 = class (TPerson3)
private
FId: Int64;
end;
TPerson5 = class (TPerson4)
private
FId: Int64;
FPhotoId: TPhoto;
end;
TPhoto = class
private
FId: Int64;
FPhotoPath: String;
end;
Thanks
Unfortunately there is no polymorphism in CreateAlias and eager loading, unfortunately. You can only do that if you do a Find<TPhoto5>, not Find<TPhoto1>
Hi
Unfortunately it does not work, because i need all type of Persons (TPerson1,TPerson2, etc..).
It's a big issue for me. Any Sugestion?
thanks
Unfortunately not, for now. The only workaround would be mapping the property as eager loading.
Hi, Wagner
Makes sense set property as eager loading in runtime before execute, and remove property after execute? (Using Datasnap + rest + json)
Something like:
if eagerLoad then
AddEagerLoad;
Result := Manager.Find<TPerson1>.List;
RemoveEagerLoad;
Thanks
thanks
You could try to do that manually manipulating the mapping in TMappingExplorer. But note that TMappingExplorer is not thread-safe, if you do that in DataSnap, you would have to create a specific TMappingExplorer for that.
Hi, Wagner
Does not work, i believe it's because MaxEagerFetchDepth=3.
thanks
If MaxEagerFetchMode is 3, then it should load, because FPhoto is just the first level (your are retrieving TPerson directly).
Hi, Wagner
instead of
"EagerExplorer.GetColumnByPropertyName(TPerson5, 'FPhotoId').IsLazy := False;"
use
"EagerExplorer.GetAssociationByPropertyName(TPerson5, 'FPhotoId').Lazy := False;"
Works fine,
thanks
This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.