CodeSmith Community
Your Code. Your Way. Faster!

My first codesmith project

Latest post 05-10-2007 5:11 PM by shannon. 1 replies.
  • 05-09-2007 12:37 AM

    My first codesmith project

    I have a lot of tables in my database that i am converting to a codesmith asp.net app. every table has a CreatedBy and ModifiedBy column that link back to a users table however there is no relationship in the database (vb6 app that assumed that the links were there).

    Is there a best practice for this scenario? there is about 50 tables in the database which would mean creating 100 relationships and creating some circular references which i don't want to do. I also don't want to have to go back to the database to get the firstname and lastname of every record when filling out a gridview.

    Has anyone delt with a situation like this one?
    Filed under: ,
    • Post Points: 35
  • 05-10-2007 5:11 PM In reply to

    • shannon
    • Top 50 Contributor
    • Joined on 03-06-2007
    • Posts 72
    • Points 4,980

    Re: My first codesmith project

    I don't think you need to add foreign keys since all of the fields are named the same. 

    You can put a check in as you are looping through the columns and provide specific functionality for these two columns.

     Something like

    <%@ CodeTemplate Language="C#" Debug="True" TargetLanguage="Html"%>
    <%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context" Description="Table that the object is based on." %>
    <%@ Assembly Name="SchemaExplorer"%>
    <%@ Import Namespace="SchemaExplorer"%>
    <%@ Import Namespace="System.Data"%>

    <%
    SchemaExplorer.TableSchema userTable = SourceTable.Database.Tables["User"];

    foreach( ColumnSchema column in SourceTable.Columns )
    {
     if( column.Name == "ModifiedBy" || column.Name == "CreatedBy" )
     {%>
      //do what is required
      <%}
    }%>

     

     

    • Post Points: 5
Page 1 of 1 (2 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems