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

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

Postby 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.
rafaelgalle11
 
Posts: 2
Joined: Wed 06 Sep 2017 20:36

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

Postby 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;
MaximG
Devart Team
 
Posts: 704
Joined: Mon 06 Jul 2015 11:34


Return to EntityDAC