3

I'm trying to use t4toolbox to generate the linq2sql classes for a project. There is already a lot of code written against the default dbml generated code.

In the LinqToSqlEntityClassTemplate.tt file it has

/// <para>
/// While MSLinqToSQLGenerator generates field names as property name with an
/// underscore prefix, this method simply converts the property name to camelCase.
/// This is done for consistency with the StyleCop rule SA1306: Variable names
/// must start with a lower-case letter.
/// </para>

Is there any way to make it generate the files in the default manner (Visual Studio way) instead of camelCasing and not having underscores?

The code generated by t4toolbox causes 400+ errors because of the field name differences.

John Boker
  • 82,559
  • 17
  • 97
  • 130

1 Answers1

1

You can copy the T4 Linq2Sql template that you want to modify in you project. You just have to make the same hierarchy as in T4Toolbox: at the root of your project, add a folder T4Toolbox/LinqToSql and copy the template LinqToSqlEntityClassTemplate.tt from your T4Toolbox install into your project. You just have to edit the FieldName methods to change the naming of fields.

project view in Visual Studio

Nekresh
  • 2,948
  • 23
  • 28
  • In the LinqToSqlEntityClassTemplate.tt I see two FieldName definitions. Both of them return FieldName(prop). Where is that FieldName() method that's transforming the property names? – John Boker Feb 18 '11 at 15:37
  • It's in the base `T4Toolbox.dll` and provide camelCasing. You'll have to change both `FieldName(Column)` and `FieldName(association)` to match your need. – Nekresh Feb 18 '11 at 15:41