// File: UsersDALBase.cspublic class UsersDALBase{ // our "generated" code here - all the CRUD operations for example.}// in another file!// File: UsersDAL.cspublic class UsersDAL : UsersDALBase{ // My custom behivors here.}
Every time I'll regenerate the code, I'll overwrite the "Base" file and no harm done - my custom changes are safe !In my "upper" layers, I always use UsersDAL(or [table]DAL for that manner) and not UsersDALBase.
Now that we've got the background, it's time to introduce to you my amigo -
CodeSmith - harness its power for your own need
<%@ CodeTemplate Language="C#" TargetLanguage="C#" Src="../OeCodeTemplate.cs" Inherits="OrenEllenbogen.Templates.OeCodeTemplate" Debug="False" Description="Generate an entity class for a given table." %> <%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Connection" Description="Table Object should be based on." %> <%@ Assembly Name="SchemaExplorer" %> <%@ Import Namespace="SchemaExplorer" %>
<% // Collection of all columns in the table. ColumnSchemaCollection Columns = new ColumnSchemaCollection(SourceTable.Columns); %>
<% // Variables by table columns. for (int i=0; i < Columns.Count; i++) { %> /// <summary> /// <%=Columns[i].Name%><%=(Columns[i].Description.Length>0) ? " : " + Columns[i].Description : ""%> /// </summary> protected <%= GetCSType(Columns[i]) %> <%=VariableStyle(Columns[i].Name)%> = <%= GetCSDefaultByType(Columns[i]) %>; <% } //end for %>
NOTE: in the new version (3.0), Eric .J. Smith, the creator of this great tool, spoiled us with brand new features like built-in IntelliSense and easier debugging options and much more.
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2009, Oren Ellenbogen
<= Contact me via E-mail
newtelligence dasBlog 2.2.8279.16125