A couple of questions and thoughts...

A couple of questions and thoughts...

Old forum URL: forums.lhotka.net/forums/t/2201.aspx


fretje posted on Tuesday, January 23, 2007

I Can't believe I'm actually the first one posting in this forum :-D

I am trying out the latest codesmith templates on codesmith 2.8 and I'm confused about something.

If I generate an EditableRootList (CurrencyList) with an EditableChild (Currency), the generated code doesn't compile, because the CurrencyList calls child.Update(cn) while the Currency object has only an Update(SqlConnection cn, CurrencyList parent) method. The CurrencyList should call child.Update(cn, this).

So I figured out... maybe I should use an EditableSwitchable in combination with an EditableRootList... This turns out to compile fine, but now there's another problem:
The CurrencyList has an override for AddNewCore in which it adds an Currency.NewCurrency(), but in this case it should call Currency.NewCurrencyChild().

Have I discovered a bug, or am I missing something?

On a sidenote: How are most of you people using these templates? I would like to have all my objects generated with partial split classes, but I haven't figured out a way to easily re-generate the code-behind files after a database-change.
At this time I'm re-entering all the properties for the template and then cut and paste the code.
In a next step I guess I would create the property set xml-file for each object and then create a batch file which calls codesmith with the xml-file as a parameter for each object.
This seems like a tedious task which can be automated further.

Now I'm mabye dreaming: wouldn't it be possible te generate the property-set into the generated file (in the comment-header or something), then it would be maybe possible with a visual studio extention to right-click on the Currency.designer.cs code-behind file and select "Re-Generate". This would be really nice ;-)

Maybe this is something to start in a new cslacontrib project...

Any Hints, comments, ... feel free!

Greetings,

fretje

fretje replied on Wednesday, January 31, 2007

105 views... seems like a lot of *silent* public...

I've been looking through some more documentation lately, and I found out about the cslaxml feature. I created an xml file for my 2 objects Currency and CurrencyList:

<?xml version="1.0" encoding="UTF-8"?>
<
CslaProject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="CslaProject.xsd">
   <
ProjectName>Business.Base</ProjectName>
   <
GenerationMethod>SplitPartial</GenerationMethod>
   <
Objects>
      <
Object Name="CurrencyList" Namespace="Business.Base" Type="EditableRootList">
         <
Relationship Child="Currency" />
      </
Object>
      
<
Object Name="Currency" Namespace="Business.Base" Type="EditableChild">
         
<
Properties>
            <
Property Name="Id" Type="int" DbColumnName="Id" IsIdentity="true" IsPrimaryKey="true" />
            <
Property Name="Description" Type="string" DbColumnName="Description" />
            <Property Name="Code" Type="string" DbColumnName="Code"/>
            <
Property Name="Rate" Type="decimal" DbColumnName="Rate"/>
         </
Properties>
         <!--
<Relationship Parent="CurrencyList" />-->
      </
Object>
   </
Objects>
</
CslaProject>

And well... It Works... if i don't put the Relationship tag in the Currency object.

If I do put it in, the Currency object gets created with the Insert and Update functions asking for a parent object reference, while the CurrencyList object always calls the Insert and the Update functions on the Currency object without passing a reference to itself. Same problem like before...

At least I can solve it now with commenting out the Relationship tag, but I think the CurrencyList object should call the insert and update functions passing a reference to itself. Why is it actually that it doesn't do that?

Concerning the automation in visual studio: I also found out about the "Custom Tool" functionality of visual studio, and the built-in Custom Tool of CodeSmith. But till this moment, I stil haven't found a practical use for it in combination with the csla templates. If someone has, I would really like to hear about it!

For now, I add an "objects.xml"-file to my project, and I created an "External tool" which calls the codesmithconsole with the cslaxml template and a generic property file (the current directory is configured as the project directory in the external tool):

<propertySet>
   <
property name="XmlFileName">Objects.xml</property>
   <
property name="OutputDirectory">.</property>
   <
property name="OutputToFile">True</property>
   <
property name="Generate">GeneratedClass</property>
   <
property name="OverrideIfExist">True</property>
</
propertySet>

I also assigned a shortcut to the external tool. This way, I can easily re-generate the files.

I'm still not happy with this solution though... no easy way of adding a new object (how to generate the user-files the first time?)... the generated files aren't "collapsable" under the user file (anybody knows how to accomplish that?), ...

It would be really nice to have a custom tool specialized for the cslaxml template. One would then be able to apply that custom tool to the "objects.xml"-file, so that the generated files are collapsable under the "objects.xml"-file and so that they are automatically regenerated, when this file changes. The only thing missing then, would be a visual designer for the objects.xml file :-D
This wouldn't be a solution for the user-files though :-S

I've been looking through some documentation about creating a Custom Tool, but it seems quite difficult: a Custom tool natively only generates one file and you have to provide it as a byte-array. The closest I found on the net was this:

http://www.codeproject.com/useritems/VsMultipleFileGenerator.asp

but it isn't really usable with the cslaxml template...

Thanks for any response!

Greetings,

fretje

Copyright (c) Marimer LLC