This is a migrated thread and some comments may be shown as answers.

Domain Model Object to Transfer Objects

1 Answer 50 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Duncan
Top achievements
Rank 2
Duncan asked on 14 Oct 2011, 07:33 PM
Is there a better way to fill a DTO from a domain model entity, or am i doing it correctly? Here is a example:

public IList<StateDTO> getStates()
{
    IList<StateDTO> stateslist = new List<StateDTO>();
 
    try
    {
        using (MyDBContext dbContext = new MyDBContext())
        {
            IList<States> states = dbContext.States.ToList();
 
            foreach (States state in states)
            {
                stateslist.Add(new StateDTO(state.StateCode, state.StateName));
            }
        }
    }
    catch (Exception ex)
    {
        //TODO: ADD ERROR LOGGING AND HANDLING
    }
 
    return stateslist;
}

1 Answer, 1 is accepted

Sort by
0
Serge
Telerik team
answered on 18 Oct 2011, 05:34 PM
Hello Duncan,

 We actually suggest using assembler classes that know how to convert to and from a DTO. This way all the logic needed for applying properties is stored in a single class. You might want to have a look at this knowledge base article that describes how you can use our T4 templates to generate a DTO layer.

Keep in mind though that we are working on a new and improved DSW wizard that will be able to generate a whole WCF Plain Service using the best practices we suggest when generating DTOs. This will be part of the Q3 release that is scheduled for mid November. 

I hope this helps. Do let us know if you have more questions.

Regards,
Serge
the Telerik team

Check out the latest stable build of Telerik OpenAccess ORM. Download it and benefit from our new Project Templates.

Tags
Development (API, general questions)
Asked by
Duncan
Top achievements
Rank 2
Answers by
Serge
Telerik team
Share this question
or