Generated Code Won't Compile - Member names cannot be the same as their enclosing type

Posts   
 
    
KentDub
User
Posts: 3
Joined: 13-Feb-2009
# Posted on: 13-Feb-2009 18:13:47   

I have an extremely large database (200+ tables), and for some reason, whoever created it would name the primary key column the exact same as the table name. I would love to change the database, but too many products are dependent on its current structure, .

When LLBLGen Pro (2.6) generates code, it creates properties inside each class named the same as the class. Why isn't everything getting auto-renamed so it would at least compile? The Microsoft VS Linq designer renames the column to "<ColumnName>1".

It seems odd that the code generator outputs code that won't compile. I thought about going through manually and renaming all of the columns within LLBLGen -- but with over 200 compiler errors caused by this it would take hours. This also would create a workflow that would be unacceptable to my managers.

Is their an option somewhere that allows you to tell LLBLGen Pro to use the same naming conventions that the Microsoft VS Linq designer uses? This would be extremely helpful for replacing our existing DBML with one from LLBLGen Pro with minimal effort. (Also, forcing the 1st character in everything to be capitalized is problimatic-- we should be able to have it be identical to the table name in the database).

Any help would be appriciated.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 13-Feb-2009 18:49:02   

KentDub wrote:

I have an extremely large database (200+ tables), and for some reason, whoever created it would name the primary key column the exact same as the table name. I would love to change the database, but too many products are dependent on its current structure, .

When LLBLGen Pro (2.6) generates code, it creates properties inside each class named the same as the class. Why isn't everything getting auto-renamed so it would at least compile? The Microsoft VS Linq designer renames the column to "<ColumnName>1".

That's because the scope to detect IF a name results in a conflict at compile time is too big, and the designer doesn't know which target language is used, which platform etc. For example, it might be a name is legal for C# 2.0, but illegal for VB.NET 9.

It seems odd that the code generator outputs code that won't compile. I thought about going through manually and renaming all of the columns within LLBLGen -- but with over 200 compiler errors caused by this it would take hours. This also would create a workflow that would be unacceptable to my managers.

I can imagine fixing this will be tedious. There's a solution though simple_smile

Create a plugin, which is very easy. Download the SDK from the customer area which contains the sourcecode of all the plugins shipped. With that sourcecode you can easily create your own plugin which walks all entities and renames all PK fields to a name pattern you like, e.g. by appending 'PK' or '1', if the name is the same as the entity. This way, you can run the plugin whenever you want and it takes just a fraction of a second.

Is their an option somewhere that allows you to tell LLBLGen Pro to use the same naming conventions that the Microsoft VS Linq designer uses? This would be extremely helpful for replacing our existing DBML with one from LLBLGen Pro with minimal effort. (Also, forcing the 1st character in everything to be capitalized is problimatic-- we should be able to have it be identical to the table name in the database).

That won't be changed, you can't have the first character not capitalized because it's against MS' guidelines. Why exactly would you want that to be? For programming against the DB it's IMHO still better to have properly named classes, e.g. with the first character capitalized, so your code will be better readable.

Frans Bouma | Lead developer LLBLGen Pro