Getting an Entity from a TypedList Row or TypedView Row

Posts   
 
    
Filomeno
User
Posts: 14
Joined: 24-Oct-2007
# Posted on: 26-Mar-2008 07:30:34   

Hello Experts, Is it possible to get an entity from a typed list or a typed view?

Ex:
    Generated TypedList:  OrderTypedList

and from there I want to get an OrderEntity from OrderTypedList somewhat like:

OrderEntity order = new OrderEntity(); OrderTypedList orderList = FindAllOrderTypedList(); -> method that will return a fetched list from database

now, order = orderList[0] as OrderEntity;

How possible it is to get an OrderEntity from a list?Or is there a method that will convert a typed list row into a specific entity?

Thanks,

jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 26-Mar-2008 13:24:42   

typedlists are meant to contain aggregated, read-only, data. if you want to work with an order in a read write fashion you should load the order from the database or build a conversion routine yourself.

public class OderTypedListToOrderEntityMapper
{
      public OrderEntity MapFrom(OrderTypedListRow item)
      {
              OrderEntity order = new OrderEntity();
              order.IsNew = false;
              foreach(IEntityField2 field in order.fields)
              {
                    order.SetCurrentFieldValue(field.Name, row[field.Name]);
              }
              return order;
      }
}

this assumes the typedlist fields match the order fields. If they do not then you will have to manually map the fields.

mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 26-Mar-2008 13:26:47   

Perhaps it would be nice to have an option in the designer where one could say: this typed list has all the data for XY entity (IOW result are those entities) and I want to see the result as entities.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 31-Mar-2008 21:23:24   

Isnt that where projections are for?

Frans Bouma | Lead developer LLBLGen Pro