tags:

views:

291

answers:

3

Do you know any T4 template which would provide me with bacis DB schema methods and properties (GetTables, GetColumns, MapSqlTypesToClr, etc.)?

I know it's easy to retrieve that information, but there are a lot of extra helper functions around it, so why reinvent the wheel?

A: 

Not sure where's the place for T4 in all that, but you can try Wizardby: it can perform database schema reverse-engineering and return a nice Schema object with all tables and columns. As for mapping DbTypes to CLR types, you'll need an appropriate IDbTypeMapper (I think SqlServer2005TypeMapper will do).

Anton Gogolev
A: 

You probably got this already but I'll leave here a possible solution.

SubSonic 3 uses T4 for code generation, its db inspector should be more than enough for you. Have a look at: http://subsonicproject.com/

AlexCode
A: 

Here is a T4 template that dumps a schema to a c# static class library that may do what you are trying to accomplish: codepaste.net snippet

I couldn't paste the code here because the syntax highlighter doesn't like T4 tags (who does?).

This will allow you to get the column name like so:

string columnName= dbSchema.Tables.Products.Columns.QuantityPerUnit.ColumnName;
robDean