Existing T4 Database Helpers for Extracting Database Schema
Do you know of any T4 template that will provide me with the basic methods and properties of a database schema ( GetTables
, GetColumns
, MapSqlTypesToClr
etc.)?
I know it's easy to get this information, but there are many additional helper functions around it, so why reinvent the wheel?
You probably got this already, but I'll leave a possible solution here.
SubSonic 3 uses T4 for code generation, its db inspector should be more than enough for you. Take a look at: http://subsonicproject.com/
a source to share
Not sure where T4 fits in all of this, but you can try Wizardby : it can reverse engineer a database schema and return a nice Schema object with all tables and columns. As far as the type mapping DbType
in the CLR is concerned , you need an appropriate one IDbTypeMapper
(I think SqlServer2005TypeMapper will do).
a source to share
Here is a T4 template that dumps a schema into a C # static class library that can do what you are trying to do: codepaste.net snippet
I couldn't paste the code here because the syntax shortcut doesn't like T4 tags (who does?).
This will allow you to get the column name like this:
string columnName= dbSchema.Tables.Products.Columns.QuantityPerUnit.ColumnName;
a source to share