Following are some steps i have followed to create DTOs using Pro:
1. Create a DTO.templatebindings using Template Studio.
Under the TemplateBindings section:
a. Open Template Studio.
b. Click on the New button.
c. Enter any Name: Dto.
d. Enter FileName: C:\Program Files\Solutions Design\LLBLGen Pro v2.0\Templates\DTO.templatebindings
e. In Platforms: Select ".Net 2.0".
Under the TemplateID section:
f. Select Target Language: C#
g. Enter TemplateID: Dto
h. Enter FileName: SharedTemplates\Net2.x\C#\dto.template
i. Enter LogiLang: TDL
j. Save and Close.
- You are now in Template Bindings Viewer tab.
- Click on Edit Selected Files button.
- Paste the following code:
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]>
}
}
- In the folder: C:\Program Files\Solutions Design\LLBLGen Pro v2.0\Tasks, create a file called DTO.Tasks
- Paste the following and save:
<?xml version="1.0"?>
name="DTO Templates" isOptional ="false"
description="General group of tasks which are used DTO templates.">
<supportedPlatforms>
<platform name=".NET 2.0" />
</supportedPlatforms>
<supportedTemplateGroups>
<templateGroup name="SelfServicing" />
</supportedTemplateGroups>
<taskGroup name="Create Directories">
<task name="DTODirectoryCreator" assemblyFilename="SD.LLBLGen.Pro.TaskPerformers.dll" taskPerformerClass="SD.LLBLGen.Pro.TaskPerformers.DirectoryCreator">
<parameters>
<parameter name="folderToCreate" defaultValue="DTO" 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>
</taskGroup>
<taskGroup name="Create DTO Classes" description="Create DTO Classes">
<!--<task name="DTOClassCreator" assemblyFilename="SD.LLBLGen.Pro.LptParser.dll" taskPerformerClass="SD.LLBLGen.Pro.LptParser.DotNetTemplateEngine">-->
<task name="DTOClassCreator" assemblyFilename="SD.LLBLGen.Pro.TaskPerformers.dll" taskPerformerClass="SD.LLBLGen.Pro.TaskPerformers.CodeEmitter">
<parameters>
<parameter isOptional="false" name="destinationFolder" defaultValue="DTO"/>
<parameter isOptional="false" name="failWhenExistent" defaultValue="false"/>
<parameter isOptional="false" name="filenameFormat" defaultValue="[elementName]DTO.[extension]"/>
<!--<parameter isOptional="false" name="templateID" defaultValue="SD_DTOTemplate"/>-->
<parameter isOptional="false" name="templateID" defaultValue="Dto"/>
<parameter isOptional="false" name="emitType" defaultValue="allEntities"/>
</parameters>
</task>
</taskGroup>
</taskGroup>
- Open any of your Llblgen Pro project.
- Select Project -> Generate
- Click on Template Bindings tab.
- You should find Dto, in the listbox Template Bindings Sorted on precedence.
- Select it.
- Click on Task queue to execute.
- Click on Add Tasks button.
- Select DTODirectoryCreator, under Create Directories, under DTO Templates.
- Click on ok.
- Scroll down and locate "SD.Tasks.Generic.FileCreators", Click on it.
- Click on Add Tasks button.
- Click on Create DTO Classes, under DTO Templates.
- Click on ok.
- Click on Generate.
Thanks.