Problems with BO generation

Problems with BO generation

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


Rizshe posted on Friday, January 16, 2009

Hi Guys,
I am using CodeSmith to generate some classes.
I'm trying to generate BO, a ReadOnlyRootList to be precise and the generation method I'm using is SplitBase only because I found problems with SplitPartial. I have an XML Template and i'm using CSLAXml.cst file to execute.
The files are generated and I do get .Base.cs and .cs files but once I put them into the code that is where my problem begins.

First problem:
The Filter Criteria class has no property although I'm specifying the properties tag in my xml template still it is empty though that is a minor issue i guess as I could change the FilterCriteria.inc to make sure that it is either overridable or something.

Second problem:
The code for .cs has a static method which I changed after changing in the FilterCriteria in.base for just checking purposes. The problem is when I tried to access it through .aspx page it doesn't work. I always get an error saying the method not found. I tried making another static method and try to access that and still it doens't work.

public static PersonPublicationList GetMyPublication(String user)
{
return DataPortal.Fetch(new FilterCriteria(user));
}

What I want to know from you Guys is in what capacity you're using CodeSmith, If you use SplitPartial how do you modify the code as most of the generated code as I assume shouldn't be modifiable so How?
OR if you use splitBase how do you implement these things...... maybe i'm missing something here.......

Thanks
Rizwan
P.S: I'm using CSLA2.0

lukky replied on Friday, January 16, 2009

Rizwan,

I'm going to follow-up on this forum so we don't crosspost to the CodeSmith forum as well.

What I'd like you to do is to generate your BO directly from the appropriate template instead of using the CSLAXml "meta" template. So in your case, use the ReadOnlyRootList.cst template directly, fill-in the properties, and see if the problems are still there. Then we can start pinpointing the source of the problem.

As I'm not using CSLA 2 myself, and as those CodeSmith templates are probably suffering from bitrot, it's important to take it one small step at a time. I've been playing lately with the CSLA 3.6 version of those templates, so I don't know if the 2.0 version have ever worked at all.

Don't forget one simple thing: you can modify the templates to fit your needs, so if they don't spit out the proper code, maybe it's time to roll-up your sleeves and learn how to write those CodeSmith templates Wink [;)]

Regards

Rizshe replied on Friday, January 16, 2009

Luc,

Thanks for your reply. I have managed to clear the error as It wasn't just the CSLA problem although for that I have to change the FilterCriteria class.
I would love to modify the templates but until I know that I'm moving in right direction I don't want to take the risk.

I don't know but I still didn't get the reply for my first question (Probably the person who designed these would answer it), What capacity you guys use CodeSmith? Do you use SplitBase or SplitPartial and If you use any of these methods then when you want to modify the code,

A) Would you override the methods
B) Would you modify the templates directly?

Regards,
Rizwan

lukky replied on Friday, January 16, 2009

I personally prefer using Partial classes/Partial methods whenever I can. I'm using it on my current project, and it works perfectly.

Of course, there is no 100% guaranteed method to generate your BOs with a single template. So whenever I need something specific for a BO or a set of BOs, I copy the template and adapt it.

Using CodeSmith project files directly in Visual Studio is of great help (requires pro version). I think the CSLAXml.cst template was kind of an attempt at emulating that beahvior, ie to have all the properties to generate a set of BOs within an XML file, and generate all BOs in one shot.

I think it's safe to say that if you're going to use templates to generate code for a "real life" project, you're most likely going to have to customize them. If you settle on CodeSmith, then it will be worth it to learn how it works, at least so you can adapt existing templates to your project.

Of course, the CSLA family of templates can be intimidating when you look at them for the first time. Been there, done that, bought the T-shirt. A good place to start is to look at the TemplateBase.cs file, as this is the base class from which all the CSLA template derive.

Regards.

rasupit replied on Saturday, January 17, 2009

Rizshe:
First problem:
The Filter Criteria class has no property although I'm specifying the properties tag in my xml template still it is empty though that is a minor issue i guess as I could change the FilterCriteria.inc to make sure that it is either overridable or something.

Add IsFilterKey="true" attribute on property tag where you want the field to be your filter criteria.

Rizshe:
Second problem:
The code for .cs has a static method which I changed after changing in the FilterCriteria in.base for just checking purposes. The problem is when I tried to access it through .aspx page it doesn't work. I always get an error saying the method not found. I tried making another static method and try to access that and still it doens't work.

I may not completely understand the issue here; In general, you must make sure that your criteria object that reside in base class must inherit from Csla.CriteriaBase and pass the bo type to base constructor.

I recommend you to take a look at the sample xml file that comes with the template suites.  When creating your own xml template source, use xml editor that can provide intellisense and make sure to reference the CslaProject.xsd.

HTH,
Ricky

Rizshe replied on Monday, January 19, 2009

Thanks Ricky,

At last I have the man who wrote the templates.

I have solved the 2nd problem by myself. It wasn't just the CSLA issue.
Ricky one question for you, which version of templates work with CodeSmith 2.6.0.117?
I am using CSLA2.0.

Thanks Luc for all the help.

Regards,
Rizwan

rasupit replied on Monday, January 19, 2009

Rizwan,

Not officially but you should give the template collection in CSLA20 folder a try.

All version of my csla templates are targeting the free version of CodeSmith. My intent is to make my templates available to everybody without requiring a purchase of CodeSmith. This decision causes me to write the code behind to must target .net framework 1.1 and missing some of the improved ways of writing template. 

The commercial version has a lot of features and I would recommend for anybody who can afford it.

I do receive feedback from users that my templates work just fine with commercial version.  Must give kudos to Eric for this.  There are some minor incompatibilities were reported and I have made a few changes in my templates to handle these quirks.  One fix that I can remember is there are version that set property value to null when left empty even it was intialize to string.empty.

Ricky

Copyright (c) Marimer LLC