- Home
- LLBLGen Pro
- Custom Templates
TypeOfRelatedEntityField Workaround
Hi, I'm triying to use de <[TypeOfField]> token in the following statement but apparently it's only defined for the currentEntityField.
<[Foreach RelatedEntityPrimaryKeyField Comma]><[TypeOfField]> <[RelatedEntityPrimaryKeyFieldName]><[NextForeach]>
I really need to know the type of a field for the currentRelatedEntityField, is there a workaround for this issue?
Gus
Please see this lpt template.
<[ System.Text ]>
<[ System.Globalization ]>
<%
Project currentProject = _executingGenerator.ProjectDefinition;
string rootNamespace = currentProject.RootNameSpace;
EntityDefinition currentEntity = (EntityDefinition)_activeObject;
%>
///////////////////////////////////////////////////////////////
// This is generated code. If you modify this code, be aware
// of the fact that when you re-generate the code, your changes
// are lost. If you want to keep your changes, make this file read-only
// when you have finished your changes, however it is recommended that
// you inherit from this class to extend the functionality of this generated
// class or you modify / extend the templates used to generate this code.
//////////////////////////////////////////////////////////////
// Code is generated using LLBLGen Pro version: 1.0.2005.1
// Code is generated on: <%=DateTime.Now.ToString()%>
// Code is generated using templates: <%=_executingGenerator.TemplateSet.Name%>
// Templates vendor: Syrtec.
// Templates version: <%=_executingGenerator.TemplateSet.Name%>
// Author: Will
// Generation: Goose
//////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using <%=rootNamespace%>.FactoryClasses;
using <%=rootNamespace%>.EntityClasses;
namespace <%=rootNamespace%>.Catalogos
{
[Serializable()]
public class Catalogo<%=currentEntity.Name%> : CatalogoBase< <%=currentEntity.Name%>Entity >
{
public Catalogo<%=currentEntity.Name%>()
: base(new <%=currentEntity.Name%>EntityFactory())
{
}
<%
// now loop through the relations of the current entity and process the m:1 relations.
foreach(EntityRelation relation in currentEntity.Relations)
{
if(relation.RelationType != EntityRelationType.ManyToOne)
{
// not a relation we're looking for
continue;
}
EntityDefinition relatedEntity = relation.RelationEndPoint;
StringBuilder methodHeaderParameters = new StringBuilder(512);
StringBuilder methodCallParameters = new StringBuilder(512);
for(int i=0;i<relatedEntity.PrimaryKeyFields.Count;i++)
{
EntityFieldDefinition pkField = (EntityFieldDefinition)relatedEntity.PrimaryKeyFields[i];
if(i>0)
{
methodHeaderParameters.Append(",");
methodCallParameters.Append(",");
}
methodHeaderParameters.AppendFormat("{0} {1}", pkField.DotNetType.ToString(), CaseCamel(pkField.FieldName));
methodCallParameters.Append(CaseCamel(pkField.FieldName));
}
%>
[System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Fill, false)]
public IList< <%=rootNamespace%>.Database.EntityClasses.<%=currentEntity.Name%>Entity > Obtener(<%=methodHeaderParameters.ToString()%>)
{
<%=rootNamespace%>.Database.EntityClasses.<%=relatedEntity.Name%>Entity <%=CaseCamel(relatedEntity.Name)%>= new <%=rootNamespace%>.Database.EntityClasses.<%=relatedEntity.Name%>Entity(<%=methodCallParameters.ToString()%>);
if (adapter.FetchEntity(<%=CaseCamel(relatedEntity.Name)%>))
{
<%=rootNamespace%>.Database.HelperClasses.EntityCollection <%=CaseCamel(currentEntity.Name)%>EntityCollection = <%=CaseCamel(relatedEntity.Name)%>.<%=currentEntity.Name%>;
adapter.FetchEntityCollection(<%=CaseCamel(currentEntity.Name)%>EntityCollection, <%=CaseCamel(relatedEntity.Name)%>.GetRelationInfo<%=currentEntity.Name%>());
foreach (<%=rootNamespace%>.Database.EntityClasses.<%=currentEntity.Name%>Entity <%=CaseCamel(currentEntity.Name)%>Entity in <%=CaseCamel(currentEntity.Name)%>EntityCollection)
{
catalogo.Add(<%=CaseCamel(currentEntity.Name)%>Entity);
}
}
return catalogo;
}
<%
}
%>
}
}
<~
private string CaseCamel(string toCaseCamel)
{
if(toCaseCamel.Length==1)
{
return toCaseCamel.ToLower(CultureInfo.InvariantCulture);
}
else
{
return toCaseCamel.Substring(0,1).ToLower(CultureInfo.InvariantCulture) + toCaseCamel.Substring(1, toCaseCamel.Length-1);
}
}
~>
Hi Frans, thanks for the support , I think ltp it's great because its so flexible but the lpt template above still throws me an exception (probably because I'm still a newbie
), I think its probably related with the configuration of the task, here are 2 screenshot of the exception:
-
The single task configurator window:
-
When I press the Run task button:
I'll also would like to add the task configuration in the task performer config file so I can run the template in regular basis, this is how I normaly do it when I was working with tdl templates:
<task name="CatalogoClassGenerator" assemblyFilename="SD.LLBLGen.Pro.TaskPerformers.dll" taskPerformerClass="SD.LLBLGen.Pro.TaskPerformers.CodeEmitter">
<parameter name="destinationFolder" value="\Catalogos\CatalogoEntidades"/>
<parameter name="failWhenExistent" value="false"/>
<parameter name="filenameFormat" value="Catalogo[elementName].[extension]"/>
<parameter name="templateID" value="Goose_Catalogo"/>
<parameter name="emitType" value="allEntities"/>
<parameter name="usePartialClasses" value="true"/>
</task>
Specify for the fieldname: [elementName]Entity.cs The destination folder is relative to the destination folder on the Generator specific info (in run single task configurator). So specify the output folder there and eventually leave the destination folder in the task parameters empty.
With that it ran fine here.
Specify for the fieldname: [elementName]Entity.cs The destination folder is relative to the destination folder on the Generator specific info (in run single task configurator). So specify the output folder there and eventually leave the destination folder in the task parameters empty.
With that it ran fine here.
...still throwing the exception
Message: Object reference not set to an instance of an object.
Stack Trace:
-----[Core exception]--------------------
at Goose_Catalogo_LPT_Test.__ScriptCode()
at Goose_Catalogo_LPT_Test.___RUN(IGenerator executingGenerator, Hashtable parameters, StreamWriter outputWriter, Object activeObject)
at SD.LLBLGen.Pro.LptParser.DotNetTemplateEngine.Perform(IGenerator executingGenerator, ITask taskDefinition, Hashtable parameters)
at SD.LLBLGen.Pro.GeneratorCore.Task.Perform(IGenerator executingGenerator, LogNode parentNode)
at SD.LLBLGen.Pro.GeneratorCore.TaskGroup.Perform(IGenerator executingGenerator, LogNode parentNode)
at SD.LLBLGen.Pro.GeneratorCore.Generator.Start(ITaskGroup tasksToExecute, Project projectDefinition, TemplateSetDefinition templateSet, ApplicationConfiguration configurationSettings)
at SD.LLBLGen.Pro.Tools.TemplateEditor.MainForm.RunTasks(ITaskGroup tasksToRun, Project projectToUse)
Works great inside the Template studio!!! I was using the emitType = generic instead of emitType =allEntities (duh).
Thanks!!
But an exception stills jumps at me in the LLBL's Designer when i try to run a customized Task performer with the following node:
<task name="CatalogoClassGenerator" assemblyFilename="SD.LLBLGen.Pro.LptParser.dll" taskPerformerClass="SD.LLBLGen.Pro.LptParser.DotNetTemplateEngine">
<parameter name="destinationFolder" value="\Catalogos\CatalogoEntidades"/>
<parameter name="failWhenExistent" value="false"/>
<parameter name="filenameFormat" value="Catalogo[elementName].[extension]"/>
<parameter name="templateID" value="Goose_Catalogo_LPT_Test"/>
<parameter name="emitType" value="allEntities"/>
<parameter name="usePartialClasses" value="true"/>
</task>
See these files for the details:
- The customized task performer: http://cs.uvg.edu.gt/~03229/AdapterScenarioFullSafe2005ByGoose.config
- An screenshot of the error:
Joined: 12-Feb-2004
<task name="CatalogoClassGenerator" assemblyFilename="SD.LLBLGen.Pro.LptParser.dll" taskPerformerClass="SD.LLBLGen.Pro.LptParser.DotNetTemplateEngine">
<parameter name="destinationFolder" value="\Catalogos\CatalogoEntidades"/>
<parameter name="failWhenExistent" value="false"/>
<parameter name="filenameFormat" value="Catalogo[elementName].[extension]"/>
<parameter name="templateID" value="Goose_Catalogo_LPT_Test"/>
<parameter name="emitType" value="allEntities"/>
<parameter name="usePartialClasses" value="true"/>
</task>
try not leading the destination folder with a slash. <parameter name="destinationFolder" value="Catalogos\CatalogoEntidades"/> Are you sure the templateID Goose_Catalogo_LPT_Test exist.