Page 1 of 1

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

Posted: Wed 06 Sep 2017 20:46
by rafaelgalle11
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.

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

Posted: Fri 08 Sep 2017 11:58
by MaximG
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;