Generating DTOs

Posts   
1  /  2
 
    
jbb avatar
jbb
User
Posts: 267
Joined: 29-Nov-2005
# Posted on: 28-May-2007 17:33:48   

Hi,

ok I misunderstand you. You have to create your task that will create the project for the DTO and so allow you to have a dll for the DTOs. You can find some sample scenario in xxx\Solutions Design\LLBLGen Pro v2.0\Tasks. The task are defined in .task files and used in the .preset files. You will find some documentation in the "SDKDocumentation->Generator and Tasks->Shipped task performer" to use the ProjectFileCreator task performer which allow you to create custom projects.

G.I.
User
Posts: 172
Joined: 09-Jun-2005
# Posted on: 19-Jun-2007 10:33:52   

I've been reading this topic, and this is exactly what I would need ... at least it look like that.

The questions I have:

If I retrieve a project entity from the database, can I convert it to a DTO or only from DTO to entity with the templates I saw in this thread?

If I have the DTO in my presentation layer, and I change the project plannedEndDate on my project DTO, and convert this in my service layer back to a ProjectEntity, is there any history? How does it know that only the plannedEndDate is changed and how does it know that when I do an update in the database that only this column should be updated?

I need this, since we use a framework and guidelines that all service layers should use DTO in case of interoperability with other applications (which are not all .Net).

sailu_tp
User
Posts: 6
Joined: 09-Sep-2006
# Posted on: 26-Jun-2007 21:54:16   

Following are the 3 steps i followed to create DTOs and i am stuck, would someone please let me know if these are the right steps and what are the following steps after these:

Step 1. Create a new file called DTO.Template in the folder "C:\Program Files\Solutions Design\LLBLGen Pro v2.0\Templates\SharedTemplates\Net2.x\C#".

Step 2. Paste this in this template file:


using System; using System.ComponentModel; using System.Collections; using System.Runtime.Serialization;

using <[RootNamespace]>.EntityClasses;

namespace <[RootNamespace]>.DTOClasses { /// <summary> /// DTO class for the entity '<[CurrentEntityName]>'. /// </summary> [Serializable] public <[If UsePartialClasses]>partial <[EndIf]>class <[CurrentEntityName]>DTO <[ If IsSubType ]>: <[ SuperTypeName ]>DTO<[ EndIf]> { #region Class Member Declarations <[Foreach EntityField CrLf]> private <[If IsNullable]><[If IsValueType]>Nullable<<[TypeOfField]>><[Else]><[TypeOfField]><[EndIf]><[Else]><[TypeOfField]><[EndIf]> _<[CaseCamel EntityFieldName]>;<[NextForeach]> #endregion

    /// <summary>
    /// CTor
    /// </summary>
    public <[CurrentEntityName]>DTO()
    {       
    }


    /// <summary>
    /// CTor which initializes the DTO with values from its corresponding entity
    /// </summary>
    /// <param name="entityInstance">The entity instance which holds the values for this DTO</param>
    public <[CurrentEntityName]>DTO(<[CurrentEntityName]>Entity entityInstance)<[ If IsSubType ]> : base(entityInstance)<[ EndIf]>
    {

<[Foreach EntityField CrLf]> _<[CaseCamel EntityFieldName]> = entityInstance.<[EntityFieldName]>;<[NextForeach]> }

    /// <summary>
    /// Creates a new entity instance and copies over the values of this DTO
    /// </summary>
    public <[CurrentEntityName]>Entity ToEntity()
    {
        return ToEntity(new <[CurrentEntityName]>Entity());
    }


    /// <summary>
    /// Copies over the values of this DTO into the entity passed in.
    /// </summary>
    public <[CurrentEntityName]>Entity ToEntity(<[CurrentEntityName]>Entity toFill)
    {

<[Foreach EntityField CrLf]> toFill.<[EntityFieldName]> = _<[CaseCamel EntityFieldName]>;<[NextForeach]> <[ If IsSubType ]> base.ToEntity(toFill);<[ EndIf]> return toFill; }

<[Foreach EntityField CrLf]> /// <summary> The <[EntityFieldName]> property of the Entity <[CurrentEntityName]></summary> public <[If EntityFieldOverrides]>override<[Else]>virtual<[EndIf]> <[If IsNullable]><[If IsValueType]>Nullable<<[TypeOfField]>><[Else]><[TypeOfField]><[EndIf]><[Else]><[TypeOfField]><[EndIf]> <[EntityFieldName]> { get { return _<[CaseCamel EntityFieldName]>;} set { _<[CaseCamel EntityFieldName]> = value; } }<[NextForeach]> } }


Step 3. In the file SD.Tasks.SelfServicing.Tasks file in the folder C:\Program Files\Solutions Design\LLBLGen Pro v2.0\Tasks added this:


<!-- folder creation tasks -->
<task name="SD.Tasks.SelfServicing.DTOClassesDirectoryCreator" assemblyFilename="SD.LLBLGen.Pro.TaskPerformers.dll" 
   taskPerformerClass="SD.LLBLGen.Pro.TaskPerformers.DirectoryCreator" description ="Creates the DTOClasses folder." isOptional="false">
    <supportedPlatforms/>
    <supportedTemplateGroups>
        <templateGroup name="SelfServicing"/>
    </supportedTemplateGroups>
    <dependencies/>
    <parameters>
        <parameter name="folderToCreate" defaultValue="DTOClasses" isOptional="false" description="The folder to create"/>
        <parameter name="failWhenExistent" defaultValue="false" isOptional="true" description="Flag to signal what to do when the folder already exists. Overrules clearWhenExistent" valueType="boolean"/>
        <parameter name="clearWhenExistent" defaultValue="false" isOptional="true" description="Flag to signal if an existing folder has to be cleared first. Overruled by failWhenExistent" valueType="boolean"/>
    </parameters>
</task>

In the above posts Frans said:


So, go to the Drivers\SqlServer\Templates folder and open CSharpTemplateset.config in notepad. (there's also a tutorial for this in the manual).

Right below the last <templateBinding> tag you add: Code:

<templateBinding templateID="EntityDTOAdapterTemplate" templateFilename="......\SharedTemplates\C#\entityDTO.template" />

The template I specified above should be saved in the file entityDTO.template and be stored in the folder SharedTemplates\C#


I looked for this file CSharpTemplateset.config but did not find it. Could anyone let me know what are the next steps also if there is anything not right in the above steps please let me know. Thanks

KS
User
Posts: 55
Joined: 08-Aug-2006
# Posted on: 02-Jul-2007 19:28:52   

If I retrieve a project entity from the database, can I convert it to a DTO or only from DTO to entity with the templates I saw in this thread?

Yeah. You can very well convert both ways from DTO to Entity -> ToEntity() Entity to DTO -> DTOConstructor with Entity as Parameter

If I have the DTO in my presentation layer, and I change the project plannedEndDate on my project DTO, and convert this in my service layer back to a ProjectEntity, is there any history? How does it know that only the plannedEndDate is changed and how does it know that when I do an update in the database that only this column should be updated?

DTO update will update everything back to db as it a dump data holder, it is not as smart as LLBL Entity.

LLBL guys, correct me if I am wrong in above replies.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 03-Jul-2007 10:30:45   

Haven't looked into the DTO template, but if it doesn't set IsChanged + IsDirty flags to true, nothing will be updated.

Frans Bouma | Lead developer LLBLGen Pro
jamesd_688
User
Posts: 1
Joined: 05-Jul-2007
# Posted on: 05-Jul-2007 20:31:13   

Otis, I am currently trialling LLBLGen. Currently very impressed.

I am currently trying to setup DTO template for the v2.0. I note that the instructions are for v1.0. Would it be possible to supply instructions for v2.0.

I need to use DTO's as I am sending data to a Flex web client using Fluorine which is an open source .NET version of Adobe AMF. This serializes dto's between the server and client.

I am already using XML in another product and would like to replace this as this requires deserialization code on the client, which is an unnecessary overhead. In order for me to purchase LLBLGen I need to use dto's in order to justify the productivity gains over the current XML deserialization methods.

Thanks,

James

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 06-Jul-2007 20:52:28   

jamesd_688 wrote:

Otis, I am currently trialling LLBLGen. Currently very impressed.

I am currently trying to setup DTO template for the v2.0. I note that the instructions are for v1.0. Would it be possible to supply instructions for v2.0.

I need to use DTO's as I am sending data to a Flex web client using Fluorine which is an open source .NET version of Adobe AMF. This serializes dto's between the server and client.

I am already using XML in another product and would like to replace this as this requires deserialization code on the client, which is an unnecessary overhead. In order for me to purchase LLBLGen I need to use dto's in order to justify the productivity gains over the current XML deserialization methods.

Please check this thread: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=8800

(and name the dto template with extension .template simple_smile )

If you're using a webservice, there will always be a xml serialization/deserialization action take place. So what you need is a class which can pass data back/forth to objects which are represented by the XML the Flex web client understands?

Frans Bouma | Lead developer LLBLGen Pro
1  /  2