Welcome Guest! To enable all features please Login or Register.



How to populate data objects from service calls
#1 Posted : Friday, September 28, 2012 6:02:40 PM(UTC)

In one of the standard design patterns, service operations pass data back and forth using data transfer objects (DTO). With multi-tier applications that use WCF as a communication layer, DTOs are the data contracts that are used for input or output structures of the service operations, since the Xomega UI data objects that serve as great view models for the forms, don't quite lend themselves to be used as data transfer objects.

Xomega Framework provides an easy way to populate UI data objects from DTOs returned by a service call. Here are the steps involved in this process.
  1. Call the method FromDataContract on your data object and pass it the DTO returned by the service operation, e.g. employeeObj.FromDataContract(svcEmployee.Read(employeeId));. By default, it will use reflection to copy all simple members of the DTO to the corresponding data properties of the data object with matching names. It will also try to populate any of the child data objects from the complex members of the DTO with the corresponding names.
  2. If the names of any data properties or child objects don't match exactly the names of the corresponding members in the DTO, then you need to override the FromDataContract method in your data object class and handle such properties or child objects individually after calling the base method. The following example demonstrates this step.
public partial class EmployeeObject 
    public const string IsCurrent = "IsCurrent";
    public const string PayHistoryList = "PayHistoryList";

    public BooleanProperty IsCurrentProperty { get; private set; }
    public DataObjectList<EmployeePayHistory> PayHistoryChildList
        get { return (DataObjectList<EmployeePayHistory>)GetChildObject(PayHistory); }

    protected override void OnInitialized()
        IsCurrentProperty = new BooleanProperty(this, IsCurrent);
        AddChildObject(PayHistoryList, new DataObjectList<EmployeePayHistory>());

    public override void FromDataContract(object dataContract)
        // call the base class to copy properties with the same names

        // copy properties and child objects where the DTO member names
        // don't match the property/child names (from constant strings).
        Employee_ReadOutput readDTO = dataContract as Employee_ReadOutput;
        if (readDTO != null)
            IsCurrentProperty.Value = readDTO.CurrentFlag;
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.