Codesmith accesses the database. The template is as follows:
Code
< % @ Codetemplate Language = "C #" Inherits = "Codesmith. basetemplates. sqlcodetemplate" Targetlanguage = "T-SQL" Description = "Generates select/insert/update/delete stored procedure based on a database schema ." % >
< % @ Property Name = "Sourcedatabase" Type = "Schemaexplorer. databaseschema" Category = "Context" Description = "Database that the stored procedures shoshould be based on ." % >
< % @ Assembly Name = "Schemaexplorer" % >
< % @ Assembly Name = "Codesmith. basetemplates" % >
< % @ Import Namespace = "Schemaexplorer" % >
< %
For (INT I = 0; I {< br>
response. writeline ("-- skipping" + sourcedatabase. tables [I]. name);
}< br> % >
references <% @ Assembly name = "schemaexplorer" %>
<% @ Assembly name = "codesmith. basetemplates "%>
<% @ import namespace =" schemaexplorer "%> Program set.
then the attribute type is declared as schemaexplorer. databaseschema attributes (database ).
later, according to sourcedatabase. tables: obtains the set of all tables of the database.
sourcedatabase. tables. count: obtain the number of database tables
sourcedatabase. tables [I]: Obtain the I table
sourcedatabase. tables [I]. name: Obtain the table name of Table I.
original works are self-worked and lazy, reprinted please explain the source of the article: http://www.cnblogs.com/kfarvid/