Page 1 of 1
Include detail objects
Posted: Sun 09 Apr 2017 13:21
by jwrz
Hi,
I have object1 with one2many association to object2. How can I force entityDAC to query from db object1 with object2 array, like .Include in C# Entity?
I have this code:
Code: Select all
var
object1 : Iobject1;
Obiekty: IEntityEnumerable;
Obiekt: TEntity;
begin
object1 := Context.object1;
Obiekty := Context.GetEntities(Linq.From(object1).Select());
for Obiekt in Obiekty do
if object2.Count>0 then
var1 := Tobject1(Obiekt).object2[0].prop1.Value;
Re: Include detail objects
Posted: Wed 12 Apr 2017 12:44
by MaximG
Unfortunately, EntityDAC does not support Eagerly loading similarly to the Include method in Entity Framework. EntityDAC only supports Lazy loading. In your sample loading of the associated collection object1.object2 will take place at the moment of checking
Re: Include detail objects
Posted: Wed 12 Apr 2017 15:49
by jwrz
OMG really? It means that one simple query can be parted in tousents.
I know that instead of that I can write own joins but it brings another issues, for example I can't use generated model IMetaType based classes as GetEntities output like I use now (prop names in code) I have to use Attribute['prop_name'] but this metod is as good as default ADOQuery+SQL.
Edit:
By the way... I have another association 1..0-1. How to check that associated object exists. Checking by "if Assigned(...) then" always return false becouse object is not queryed from DB.
Re: Include detail objects
Posted: Thu 13 Apr 2017 10:12
by MaximG
We will consider implementing the Include method in EntityDAC. You can leave your suggestion at our UserVoice page (
https://devart.uservoice.com/forums/240996-entitydac ). We will implement this behavior in case if the proposed functionality is of interest to our users.
In EntityDAC Lazy loading is also implemented for the One-To-One relation. According to your sample when attempting to execute
Code: Select all
if Assigned(ObjectOne.ObjectTwo) then
, an associated object will be loaded at the moment of referring to
and Assigned will return True if the associated object exists