- Home
- LLBLGen Pro
- Custom Templates
DTO Templates for v2.5 ?
Joined: 02-Oct-2007
Hello,
I am trying to use the DTO template that is listed in the forums on LLBL Pro 2.5; I have copied the exact code and followed all the steps for setting up the template as a "AdditionalTemplate". However, when I generate code I get a "Object not set to an instance of the object" error. Will the 2.0 template work in 2.5 without any changes or am I missing something ?
Object reference not set to an instance of an object.
-----[Core exception]--------------------
at SD.LLBLGen.Pro.LptParser.DotNetTemplateEngine.Perform(IGenerator executingGenerator, ITask taskDefinition, Dictionary`2 parameters)
at SD.LLBLGen.Pro.ApplicationCore.Tasks.Task.Perform(IGenerator executingGenerator, LogNode parentNode)
at SD.LLBLGen.Pro.ApplicationCore.Tasks.TaskGroup.Perform(IGenerator executingGenerator, LogNode parentNode)
at SD.LLBLGen.Pro.ApplicationCore.Tasks.TaskGroup.Perform(IGenerator executingGenerator, LogNode parentNode)
at SD.LLBLGen.Pro.ApplicationCore.Tasks.TaskGroup.Perform(IGenerator executingGenerator, LogNode parentNode)
at SD.LLBLGen.Pro.GeneratorCore.Generator.Start(ITaskGroup tasksToExecute, Project projectDefinition, Language languageToUse, Platform platformToUse, List`1 templateBindingsToUse, String templateGroupToUse, ApplicationConfiguration configurationSettings)
at SD.LLBLGen.Pro.Gui.Forms.MainWindow.StartGeneratorProcess()
Thanks Kiran
Joined: 02-Oct-2007
I got it from here...... the second version with the Nullable support..... http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=6261
Here's what I did..... 1. In AdditionalTemplates folder - Added SD.AdditionalTemplates.DTO.NET20.templatebindings - Added DTO folder - Added DTOTemplate.tdl
-
In Tasks folder - Added DTOTemplate.Tasks
-
Included the DTO Tasks in the Task Queue while generating code
Thanks for your help Kiran
SD.AdditionalTemplates.DTO.NET20.templatebindings.....
<?xml version="1.0" encoding="utf-8"?>
<templateBindings name="DTO Template" description="Manager templates" precedenceLevel="10" databaseDriverID="2D18D138-1DD2-467E-86CC-4838250611AE" xmlns="http://sd/llblgen/pro/templateBindingsDefinition.xsd">
<supportedPlatforms>
<platform name=".NET 2.0" />
</supportedPlatforms>
<language name="C#">
<templateBinding templateID="SD_DTOTemplate" filename="DTO\DTOTemplate.tdl" />
</language>
</templateBindings>
DTOTemplate.tdl.....
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]>
}
}
DTO.Template.Taks.......
<?xml version="1.0"?>
<taskGroup xmlns="http://sd/llblgen/pro/taskGroupElementDefinitions.xsd"
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="Adapter" />
</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">
<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="emitType" defaultValue="allEntities"/>
</parameters>
</task>
</taskGroup>
</taskGroup>
Joined: 21-Aug-2005
Please check the following most recent thread about the steps to generate the DTOs: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=10504
Joined: 20-Jun-2007
Hi,
I'm getting the same exception you've reported here.
I'm using the template, templatebinding, task described in: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=10504.
Any idea how to resolve the issue?
-----[Core exception]--------------------
at SD.LLBLGen.Pro.LptParser.DotNetTemplateEngine.Perform(IGenerator executingGenerator, ITask taskDefinition, Dictionary2 parameters)
at SD.LLBLGen.Pro.ApplicationCore.Tasks.Task.Perform(IGenerator executingGenerator, LogNode parentNode)
at SD.LLBLGen.Pro.ApplicationCore.Tasks.TaskGroup.Perform(IGenerator executingGenerator, LogNode parentNode)
at SD.LLBLGen.Pro.ApplicationCore.Tasks.TaskGroup.Perform(IGenerator executingGenerator, LogNode parentNode)
at SD.LLBLGen.Pro.ApplicationCore.Tasks.TaskGroup.Perform(IGenerator executingGenerator, LogNode parentNode)
at SD.LLBLGen.Pro.GeneratorCore.Generator.Start(ITaskGroup tasksToExecute, Project projectDefinition, Language languageToUse, Platform platformToUse, List
1 templateBindingsToUse, String templateGroupToUse, ApplicationConfiguration configurationSettings)
at SD.LLBLGen.Pro.Tools.TemplateEditor.MainForm.RunTasks(Generator toRun, ITaskGroup tasksToRun, Project projectToUse)
I also tried stripping the dto.template to an empty shell (and still get the same exception):
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]> {
}
}
Joined: 17-Aug-2003
The DotNetTemplateEngine is for .lpt templates, your template uses TDL statements. You should use the task to consume a TDL template and execute the task with that. Could you try that please?
Joined: 20-Jun-2007
Yes, that fixed it up. Thanks! Attached are the templatebinding, template, and tasks for other's future reference.
Template Binding (DTO.templatebindings)...
<?xml version="1.0"?>
<templateBindings xmlns="http://sd/llblgen/pro/templateBindingsDefinition.xsd" name="My DTO template bindings" description="My Monday DTO template bindings" precedenceLevel="11" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://sd/llblgen/pro/templateBindingsDefinition.xsd
C:\PROGRA~1\SOLUTI~1\LLBLGE~1.5\Tasks\XSDs\templateBindingsDefinition.xsd">
<supportedPlatforms>
<platform name=".NET 2.0"/>
</supportedPlatforms>
<language name="C#">
<templateBinding templateID="Dto" filename="SharedTemplates\Net2.x\C#\Dto.template"/>
</language>
<language name="VB.NET">
<!-- If you're using VB.NET, you've should add the binding above here instead. -->
</language>
</templateBindings>
Template (DTO.template)...
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()
{
int junkTest = 1;
}
/// <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]>
}
}
Tasks (DTO.tasks)...
<?xml version="1.0"?>
<taskGroup xmlns="http://sd/llblgen/pro/taskGroupElementDefinitions.xsd" name="DTO Templates" isOptional="false" description="General group of tasks which are used DTO templates." xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://sd/llblgen/pro/taskGroupElementDefinitions.xsd
C:\PROGRA~1\SOLUTI~1\LLBLGE~1.5\Tasks\XSDs\taskGroupElementDefinitions.xsd">
<supportedPlatforms>
<platform name=".NET 2.0"/>
</supportedPlatforms>
<supportedTemplateGroups>
<templateGroup name="Adapter"/>
</supportedTemplateGroups>
<dependencies/>
<taskGroup name="Create Directories" description="DTO Directory Creator TaskGroup" isOptional ="true" requiresCleanCache="true">
<task name="DTODirectoryCreator" assemblyFilename="SD.LLBLGen.Pro.TaskPerformers.dll" taskPerformerClass="SD.LLBLGen.Pro.TaskPerformers.DirectoryCreator" description="DTO Directory Creator Task" isOptional ="true" requiresCleanCache="true">
<supportedPlatforms>
<platform name=".NET 2.0"/>
</supportedPlatforms>
<supportedTemplateGroups>
<templateGroup name="Adapter"/>
</supportedTemplateGroups>
<dependencies/>
<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" isOptional="true">
<!--<task name="DTOClassCreator" assemblyFilename="SD.LLBLGen.Pro.LptParser.dll" taskPerformerClass="SD.LLBLGen.Pro.LptParser.DotNetTemplateEngine" description="DTO Class Creator Task" isOptional="true">-->
<task name="DTOClassCreator" assemblyFilename="SD.LLBLGen.Pro.TaskPerformers.dll" taskPerformerClass="SD.LLBLGen.Pro.TaskPerformers.CodeEmitter" description="DTO Class Creator Task" isOptional="true">
<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>
Joined: 02-Oct-2007
you might want to also check for readonly (autoincrement) fields when assigning to/from entities, otherwise it wont compile....
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]><[If Not IsReadOnly]> toFill.<[EntityFieldName]> = _<[CaseCamel EntityFieldName]>;<[EndIf]><[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]>;}
<[If Not IsReadOnly]>set { _<[CaseCamel EntityFieldName]> = value; }<[EndIf]>
}<[NextForeach]>
}
}