Is there any way that we can customize code generated by EntityToDtos

Feb 28, 2013 at 5:27 AM
I have visited (http://social.msdn.microsoft.com/Forums/en-US/silverlightwcf/thread/418e7ac2-75c8-45ca-8f55-54684609cf79/) shows that Dto can load only data that is only required by view.

So I search for DTOs.

& I found your wonderful tool.
I want to know that can we customize code generated by the tool?

Meance which property should be there in dto class & Any addtional property that I want to add to dto class.
Is it possible?

If possible then can you give any sample shows how to use ths DTO class for loading data in view that is required. not all data loaded
Coordinator
Feb 28, 2013 at 11:40 AM
Edited Mar 5, 2013 at 1:12 AM
Hello Vipul!

Thanks for using EntitiesToDTOs!

Regarding optionally selecting the properties that the DTO should have is a suggested Feature and not available at the moment, you can vote up the corresponding Feature.

About adding aditional properties to the DTO, yes you can do it without problems. All DTOs generated by the tool are defined as partial classes which means that you can extend them anyway you want, adding properties, members, constructors, etc. You just need to create a new file (because the file where the DTO was generated will get overwriten when you generate again), define the same partial class (DTO) as defined by the tool and code whatever you need in there.

Example
Generated by the tool in "Solution/MyClassLibrary/MyDTOs.cs":
//-------------------------------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by EntitiesToDTOs.v3.0 (entitiestodtos.codeplex.com).
//     Timestamp: 2012/11/14 - 21:32:58
//
//     Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
// </auto-generated>
//-------------------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;

namespace MyClassLibrary
{
    public partial class PersonDTO
    {
        public Int64 PersonID { get; set; }

        public String FirstName { get; set; }

        public PersonDTO()
        {
        }

        public PersonDTO(Int64 personID, String firstName)
        {
            this.PersonID = personID;
            this.FirstName = firstName;
        }
    }
}
And coded by you in "Solution/MyClassLibrary/MyExtendedDTOs.cs":
using System;
using System.Collections.Generic;
using System.Text;

namespace MyClassLibrary
{
    public partial class PersonDTO
    {
        public String LastName { get; set; }

        public PersonDTO(Int64 personID, String firstName, String lastName) 
            : this(personID, firstName)
        {
            this.LastName = lastName;
        }
    }
}
Above you can see an example of partial class usage, for DTOs I would not include much more than aditional properties and constructors because the purpose of them is to not have any logic (no additional methods) an be lightweight.

Let me know if you got any doubts.
Marked as answer by ffernandez on 12/30/2013 at 6:53 PM