How to convert IentityEnumerable<T> to TObjectList<T>

Discussion of open issues, suggestions and bugs regarding EntityDAC
Post Reply
rafaelgalle11
Posts: 2
Joined: Wed 06 Sep 2017 20:36

How to convert IentityEnumerable<T> to TObjectList<T>

Post by rafaelgalle11 » Wed 06 Sep 2017 20:46

Hellow

I'm starting to use EntityDAC and need to convert IentityEnumerable <T> to TObjectList <T>

Or somehow perform queries populating a TObjectList <T> and not an IentityEnumerable <T> as the examples show ...

var
   FTest: IentityEnumerable <TTest>;
begin
   FTest: = FContext.GetEntities <TTest>;

Can you help me?
Thank you for your attention.

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

Re: How to convert IentityEnumerable<T> to TObjectList<T>

Post by MaximG » Fri 08 Sep 2017 11:58

You cannot immediately convert IentityEnumerable <T> to TObjectList <T>. However, it's very simple to do it in your project code. The following snippet demonstrates such a possibility:

Code: Select all

...
var
  i: integer;
  EntityCollection: IEntityEnumerable;
  List: TObjectList<TEntity>;
begin
  List := TObjectList<TEntity>.Create;
  try
    for i := 0 to EntityCollection.Count - 1 do
      List.Add(EntityCollection.Elements[i]);

      ...

  finally
    List.Free;
  end;
end;

Post Reply