How to Convert to DTO?

Thread is closed for posting
2 posts, 0 answers
  1. G. Deward
    G. Deward avatar
    9 posts
    Member since:
    Jan 2012

    Posted 20 May 2012 Link to this post

    How can I convert persistant objects to DTOs using the projects generated with the "Generate OpenAccess Domain Model Service" wizard?  I have attempted to use the Assembler classes, however they do not assemble any of the child objects:

    public IEnumerable<CountryDto> FetchCountryHeirarchy()
        using (var context = new GlobalResourcesEntitiesModel())
            FetchStrategy strategy = new FetchStrategy();
            strategy.LoadWith<Country>(c => c.States);
            strategy.LoadWith<State>(s => s.Cities);
            context.FetchStrategy = strategy;
            IQueryable<Country> items = from c in context.Countries
                                        select c;
            CountryAssembler ass = new CountryAssembler();
            return ass.Assemble(items);

    I have the following projects:

    • MyApp.ActionService (hosts complex business actions / operations)
    • MyApp.DataService (created by TelerikORM for CRUD operations)
    • MyApp.Business (used for complex operations)
    • MyApp.Data (EntityModel is here)

    My goal is to pass the same DTO objects from either service.  This allows me to protect the data service from direct data calls and expose a more complex operation with the ActionService.  My hope is to encapsulate all of the complex operations in either the ActionService or Business layer project while still passing the DTOs that Telerik ORM has generated in the Data Service.

    At the moment, both the Business layer project and ActionService are using standard LINQ syntax against the EntityModel (context) directly.  This returns the objects from the RLINQ file and NOT the DTOs.  I would like to convert them to DTOs before sending them across the wire.

    Thanks, in advance.

    - Greg D.

  2. Viktor Zhivkov
    Viktor Zhivkov avatar
    324 posts

    Posted 23 May 2012 Link to this post

    Hi Greg,

    Your question about navigation properties in the DTO layer comes just in time.
    We have implemented support for these properties recently and they will be available in the next official release coming in the beginning of June.

    For now you can replace the code generation templates that produce the DTO types with the newly updated ones from the attachment.
    In order to do so, you can extract the zip archive overwriting the DTO folder at:
    <Your OpenAccess install dir>\dsl2010\CodeGenerationTemplates\Dto 
    (usually it is C:\Program Files\Telerik\OpenAccess ORM\dsl2010\CodeGenerationTemplates\Dto)
    I would recommend that you create a backup copy of the original templates before overwriting them. 
    If you have made any customizations to these templates please contact us so we can find a way how to merge the changes safely.

    Please note that we provide support for navigation properties in the Entity to DTO direction only. This is a design consideration, because usually update (DTO to Entity) business logic usually is application specific and we prefer it to be handled by the developer.

    As an early adopter of the new feature we would like to hear your feedback and suggestions so we can make the service generation even more attractive to other OpenAccess developers. 

    Viktor Zhivkov
    the Telerik team
    Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
Back to Top