Include detail objects

Discussion of open issues, suggestions and bugs regarding EntityDAC
Post Reply
jwrz
Posts: 19
Joined: Mon 22 Aug 2016 05:30

Include detail objects

Post by jwrz » Sun 09 Apr 2017 13:21

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;

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: Include detail objects

Post by MaximG » Wed 12 Apr 2017 12:44

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

Code: Select all

if object2.Count > 0 then

jwrz
Posts: 19
Joined: Mon 22 Aug 2016 05:30

Re: Include detail objects

Post by jwrz » Wed 12 Apr 2017 15:49

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.

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: Include detail objects

Post by MaximG » Thu 13 Apr 2017 10:12

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

Code: Select all

ObjectOne.ObjectTwo
and Assigned will return True if the associated object exists

Post Reply