TypedList & projection

Posts   
 
    
jlozina
User
Posts: 17
Joined: 13-Mar-2008
# Posted on: 16-Apr-2008 16:00:18   

Hi,

I'm wondering how do you project a TypedList to a custom class/DTO.

The Code I am using are

LkpClassificationTypedList classification = new LkpClassificationTypedList(); adapter.FetchTypedList(classification);

Fields for the Entity are

(LkpClassificationFields.Code, 0, "Code", "", AggregateFunction.None); (LkpClassificationFields.Description, 1, "Description", "", AggregateFunction.None); (LkpClassificationFields.Rate, 2, "Rate", "", AggregateFunction.None); (LkpClassificationFields.Enabled, 3, "Enabled", "", AggregateFunction.None); (LkpClassificationFields.DisplayOrder, 4, "DisplayOrder", "", AggregateFunction.None);

Thanks, Joe

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 16-Apr-2008 16:13:28   

Please try the following:


MyTypedList myTypedList = new MyTypedList();

List<CustomCustomer> customClasses = new List<CustomCustomer>();

DataProjectorToCustomClass<CustomCustomer> projector = 
    new DataProjectorToCustomClass<CustomCustomer>( customClasses );

// Define the projections of the fields.    
List<IDataValueProjector> valueProjectors = new List<IDataValueProjector>();
valueProjectors.Add( new DataValueProjector( "City", 0, typeof( string ) ) );
valueProjectors.Add( new DataValueProjector( "CompanyName", 1, typeof( string ) ) );
valueProjectors.Add( new DataValueProjector( "CustomerID", 2, typeof( string ) ) );
valueProjectors.Add( new DataValueProjector( "Country", 3, typeof( string ) ) );

// perform the fetch combined with the projection.
using( DataAccessAdapter adapter = new DataAccessAdapter() )
{
    adapter.FetchProjection( valueProjectors, projector, myTypedList.GetFieldsInfo(), myTypedList.GetRelationInfo(), 0, true );
}

Where the custom class is:

public class CustomCustomer
{
    #region Class Member Declarations
    private string _customerID, _companyName, _city, _country;
    #endregion

    public CustomCustomer()
    {
        _city = string.Empty;
        _companyName = string.Empty;
        _customerID = string.Empty;
        _country = string.Empty;
    }

    #region Class Property Declarations
    public string CustomerID
    {
        get { return _customerID; }
        set { _customerID = value; }
    }

    public string City
    {
        get { return _city; }
        set { _city = value; }
    }

    public string CompanyName
    {
        get { return _companyName; }
        set { _companyName = value; }
    }

    public string Country
    {
        get { return _country; }
        set { _country = value; }
    }
    #endregion
}
jlozina
User
Posts: 17
Joined: 13-Mar-2008
# Posted on: 17-Apr-2008 01:36:19   

Great, that works fine.

Ive noticed that the DTO task generator only creates DTO's based on entities. Does it also create DTO classes from typedLists?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 17-Apr-2008 10:19:40   

Does it also create DTO classes from typedLists?

There is no need for that, as TypedLists are actually dataTables.