asp.net模型层,CodeSmith代码自动生成模版
<%@ CodeTemplate Language="C#" TargetLanguage="C#" Description="Generates a very simple business object." %> <%@ Property Name="TargetTable" Type="SchemaExplorer.TableSchema" Category="Context" Description="TargetTable that the object is based on." %> <%@ Property Name="ModelsNamespace" Default="MyBookShop.Model" Type="System.String" Category="Context" Description="TargetTable that the object is based on." %> <%@ Assembly Name="SchemaExplorer" %> <%@ Assembly Name="System.Data" %> <%@ Import Namespace="SchemaExplorer" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Text.RegularExpressions" %> <% PrintHeader(); %> using System; using System.Collections.Generic; using System.Text;
namespace <%= ModelsNamespace %> { ? ?[Serializable()] ?public class <%= GetModelClassName() %> ?{ ? ??private <%= GetPKPropertyType() %> <%= GetPKMemberVarName() %>; ??<% ?? ??if(TargetTable.ForeignKeys.Count > 0) ??{ ???foreach (TableKeySchema key in TargetTable.ForeignKeys) ???{ ??%> ??private <%= GetFKPropertyType(key) %> <%= GetFKMemberVarName(key) %>; ??<% ???}??? ??} ?? ??foreach (ColumnSchema column in TargetTable.NonKeyColumns) ???{ ???if(GetMemberVariableDefaultValue(column) != "") ???{ ??%> ??private <%= GetPropertyType(column) %> <%= GetMemberVarName(column) %> = <%= GetMemberVariableDefaultValue(column) %>; ??<% ???} ???else ???{ ??%> 节省页面省去后续大量代码......下载CodeSmith代码模板文件dbmadmodels
asp.net三层架构数据访问层,CodeSmith代码自动生成模版
<%@ CodeTemplate Language="C#" TargetLanguage="C#" Description="Generates a very simple business object." %> <%@ Property Name="TargetTable" Type="SchemaExplorer.TableSchema" Category="Context" Description="TargetTable that the object is based on." %> <%@ Property Name="ModelsNamespace" Default="MyBookShop.Model" Type="System.String" Category="Context" Description="TargetTable that the object is based on." %> <%@ Property Name="DALNamespace" Default="MyBookShop.DAL" Type="System.String" Category="Context" Description="TargetTable that the object is based on." %> <%@ Property Name="DALClassNameSurfix" Default="DAL" Type="System.String" Category="Context" Description="TargetTable that the object is based on." %> <%@ Assembly Name="SchemaExplorer" %> <%@ Assembly Name="System.Data" %> <%@ Import Namespace="SchemaExplorer" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Text.RegularExpressions" %> <% PrintHeader(); %> using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Data.SqlClient; using <%= ModelsNamespace %>; namespace <%= DALNamespace %> { ?public class <%= GetDALClassName() %> ?{ ??<%-- public? Book AddBook(Book book) --%> ??????? public? int Add<%= GetModelClassName() %>(<%= GetModelClassName() %> <%= GetModelParamName() %>) ??{ ??????????? string sql = ????<%= GetInsertSQLLine1()%> ????<%= GetInsertSQLLine2()%> ???? ???sql += " ; SELECT @@IDENTITY"; ??????????? try ??????????? { ????SqlParameter[] para = new SqlParameter[] ????{ ?????<% ?????foreach(TableKeySchema key in TargetTable.ForeignKeys) ?????{ ?????%> ?????new SqlParameter("@<%= GetFKForeignIdName(key) %>", <%= GetModelParamName() %>.<%= GetFKPropertyName(key) %>.<%= GetFKPrimaryIdName(key) %>), //FK ?????<% ?????} ?????for(int i=0; i<TargetTable.NonKeyColumns.Count-1; i++) ?????{ ??????ColumnSchema column = TargetTable.NonKeyColumns[i]; ?????%> ?????new SqlParameter("@<%= column.Name %>", <%= GetModelParamName() %>.<%= column.Name %>), ?????<% ?????} ?????for(int i=TargetTable.NonKeyColumns.Count-1; i<TargetTable.NonKeyColumns.Count; i++) ?????{ ??????ColumnSchema lastColumn = TargetTable.NonKeyColumns[i]; ?????%> ?????new SqlParameter("@<%= lastColumn.Name %>", <%= GetModelParamName() %>.<%= lastColumn.Name %>) ?????<% ?????} ?????%> ????}; ???? ??????????????? int row = SqlHelper.ExecuteSql(sql, para); ????return row; ??????????? } ??????????? catch (Exception e) ??????????? { ??????????????? throw e; ??????????? } ??} ?? ??节省页面省去后续大量代码......下载CodeSmith代码模板文件dbmaddal
asp.net三层架构业务层,CodeSmith代码自动生成模版
<%@ CodeTemplate Language="C#" TargetLanguage="C#" Description="Generates a very simple business object." %> <%@ Property Name="TargetTable" Type="SchemaExplorer.TableSchema" Category="Context" Description="TargetTable that the object is based on." %> <%@ Property Name="ModelsNamespace" Default="MyBookShop.Model" Type="System.String" Category="Context" Description="TargetTable that the object is based on." %> <%@ Property Name="DALNamespace" Default="MyBookShop.DAL" Type="System.String" Category="Context" Description="TargetTable that the object is based on." %> <%@ Property Name="BLLNamespace" Default="MyOffice.BLL" Type="System.String" Category="Context" Description="TargetTable that the object is based on." %> <%@ Property Name="BLLClassNameSurfix" Default="Manager" Type="System.String" Category="Context" Description="TargetTable that the object is based on." %> <%@ Property Name="DALClassNameSurfix" Default="DAL" Type="System.String" Category="Context" Description="TargetTable that the object is based on." %> <%@ Assembly Name="SchemaExplorer" %> <%@ Assembly Name="System.Data" %> <%@ Import Namespace="SchemaExplorer" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Text.RegularExpressions" %> <% PrintHeader(); %> using System; using System.Collections.Generic; using System.Text; using <%= DALNamespace %>; using <%= ModelsNamespace %>; namespace <%= BLLNamespace %> { ??? public class <%= GetBLLClassName() %> ??? { ??private static readonly <%= GetDALClassName() %> dal = new <%= GetDALClassName() %>(); ??????? public? int Add<%= GetModelClassName() %>(<%= GetModelClassName() %> <%= GetModelParamName() %>) ??????? { ???<% ???if(TargetTable.ForeignKeyColumns.Count>0) ???{ ????foreach(TableKeySchema key in TargetTable.ForeignKeys) ????{ ?????if(key.PrimaryKeyTable.ExtendedProperties.Contains("DefaultId")) ?????{ ???%> ??????????? if (<%= GetModelParamName() %>.<%= GetFKPropertyName(key) %> == null) ??????????? { ??????????????? <%= GetModelParamName() %>.<%= GetFKPropertyName(key) %> = new <%= 节省页面省去后续大量代码......下载CodeSmith代码模板文件dbmadbll
最新评论
4 周 17 小时之前
4 周 17 小时之前
4 周 1 天之前
5 周 1 天之前
5 周 1 天之前
5 周 1 天之前
5 周 1 天之前
5 周 5 天之前
6 周 5 天之前
6 周 5 天之前