Codesmith, netTiers and reserved words

Started today using Codesmith tools today after a year or so since the last time that I used this great generation template based tool.

I had to generate all the layers of an existent portal and I decided to use the netTiers templates to accomplish this task.

And here are the problems that I had to solve:

  • In the Entities templates:

I have a table named Entity that conflicts with the auxiliary class of the netTiers templates. It seems that the templates already generate a class called Entity and because there is a table called Entity there was a conflict.

I solved that using the alias text file feature of the templates that allows me to define a alias for any table that I have. So I just inserted a new line in my alias text file like this:

Entity:MyEntity

With this alias, netTiers generated a class for my table named MyEntity that didn't conflict with his own class Entity.

  • In the Data templates:

I had a table with two foreign keys. But the problem was that the foreign keys were on the same column of the table but referencing two different tables.

The problem was that netTiers generated two methods with the same name and signature GetByColumnForeingKey.

I had to change the schema and use two columns, each one referencing a different column in a different table.

  • In the Domain templates:

I have views in my database and I had compilation problems with the generated classes for these views.

For each view there are two generated files/classes:

MyView.cs and MyViewServiceBase.generated.cs

Where MyView inherits from MyViewBase. Because MyViewBase doesn't exist there was a compilation problem. I just had to strip the "Service" word from the netTiers templates so the file/class generated was MyViewBase.cs instead of MyViewServiceBase.cs

Another problem was with a table with a "Type" column. This gives this error:

Error    1    An object reference is required for the non-static field, method, or property 'TableBase.Type.get'    Domain\TableBase.generated.cs    1394    57    Domain

The generated code was

DeepLoad(entity, false, DeepLoadType.ExcludeChildren, Type.EmptyTypes);

I had to change the template so to genreate

DeepLoad(entity, false, DeepLoadType.ExcludeChildren, System.Type.EmptyTypes);

  • In the Data.SqlClient templates:

There was an ambiguous table named Parameter. netTiers already creates a class named Parameter so I just had to add another line in my alias text file

Parameter:MyParameter

  • And finally in the web templates:

There was an ambiguous table named Page. I just had to add another line in my alias text file.

Page:MyPage