Domain Model Object to Transfer Objects

Thread is closed for posting
2 posts, 0 answers
  1. Duncan
    Duncan avatar
    93 posts
    Member since:
    Jul 2012

    Posted 14 Oct 2011 Link to this post

    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>();
            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)
        return stateslist;
  2. Serge
    Serge avatar
    375 posts

    Posted 18 Oct 2011 Link to this post

    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.

    the Telerik team

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

Back to Top