我想问一下业务数据库有32张表,那么BLL IDAL DAL MODEL层要各写32个模版吗即128个模版吗? 还有生成的代码怎麽自动生成cs文件,然后把生成的代码输出到cs文件里面,在网上找了一篇文章 试过不行 文章地址:http://terrylee.cnblogs.com/archive/2005/12/28/306233.html
本人是codesmith初学者希望各位大侠帮忙 还有希望可以根据我下面给出的cs文件给出codesmith模版,谢谢大家了
1 ------CT_Append_BLL.cs--------------------------------------------------------------------- 2 // =================================================================== 3 // Name: DataAccess Factory 4 // Author: 小华 5 // DateTime: 2011-07-08 6 // Description: DataAccess.cs 7 // =================================================================== 8 using System; 9 using System.Collections.Generic; 10 using GPOS.Components; 11 using GPOS.Model; 12 using GPOS.IDAL; 13 using GPOS.DALFactory; 14 15 namespace GPOS.BLL 16 { 17 public class CT_Append 18 { 19 private static readonly ICT_Append dal = DataAccess.CreateCT_Append(); 20 21 // <summary> 22 // 添加充值 23 // </summary> 24 // <param name="CT_AppendInfo">充值信息</param> 25 // <returns></returns> 26 public static int Create(CT_AppendInfo _CT_AppendInfo) 27 { 28 if (_CT_AppendInfo == null) 29 return 0; 30 else 31 return dal.Create(_CT_AppendInfo); 32 33 } 34 35 36 // <summary> 37 // 删除充值记录 38 // </summary> 39 // <param name="vC_A_SNNO">充值交易序号</param> 40 // <returns></returns> 41 public static int Remove(string vC_A_SNNO) 42 { 43 return dal.Remove(vC_A_SNNO); 44 45 } 46 47 // <summary> 48 // 根据交易序号获取一条充值信息 49 // </summary> 50 // <param name="vC_A_SNNO">充值交易序号</param> 51 // <returns></returns> 52 public static CT_AppendInfo GetById(string vC_A_SNNO) 53 { 54 return dal.GetById(vC_A_SNNO); 55 56 } 57 58 // <summary> 59 // 获取一个分页列表 60 // </summary> 61 // <param name="TotalRecords">行数</param> 62 // <param name="PageIndex">索引</param> 63 // <returns></returns> 64 public static PageSetInfo Get(int TotalRecords, int PageIndex) 65 { 66 if (TotalRecords > 0 && PageIndex > 0) 67 return dal.Get(TotalRecords, PageIndex); 68 else 69 return null; 70 } 71 72 73 /// <summary> 74 /// 查询充值记录 75 /// </summary> 76 /// <param name="VC_A_SNNO">充值交易序号</param> 77 /// <param name="VC_OC_UserName">客户名称</param> 78 /// <param name="VC_OC_Company">单位</param> 79 /// <param name="VC_A_CardNO">卡号</param> 80 /// <param name="CardType">卡片类型</param> 81 /// <param name="VC_A_AppendType">充值类型</param> 82 /// <param name="VC_TicketType">发票类型</param> 83 /// <param name="VC_TicketNO">发票编号</param> 84 /// <param name="StartDate">开始日期</param> 85 /// <param name="EndDate">结束日期</param> 86 /// <param name="TotalRecords">每页的条数</param> 87 /// <param name="PageIndex">页数</param> 88 /// <returns></returns> 89 public static PageSetInfo Search(string VC_A_SNNO, string VC_OC_UserName, string VC_OC_Company, string VC_A_CardNO, int CardType, string VC_A_AppendType, string VC_TicketType, string VC_TicketNO, string StartDate, string EndDate, int TotalRecords, int PageIndex) 90 { 91 return dal.Search(VC_A_SNNO, VC_OC_UserName, VC_OC_Company, VC_A_CardNO, CardType, VC_A_AppendType, VC_TicketType, 92 VC_TicketNO, StartDate, EndDate, TotalRecords, PageIndex); 93 } 94 /// <summary> 95 /// 客户IC卡充值明细报表查询 96 /// </summary> 97 /// <param name="VC_A_CardNO">客户卡号</param> 98 /// <param name="VC_OC_UserName">客户名称</param> 99 /// <param name="VC_OC_Company">客户单位</param> 100 /// <param name="I_A_CardType">卡片类型</param> 101 /// <param name="StartDate">开始日期</param> 102 /// <param name="EndDate">结束日期</param> 103 /// <param name="TotalRecords">每页的记录数</param> 104 /// <param name="PageIndex">当前页数</param> 105 /// <returns></returns> 106 public static PageSetInfo Search(string VC_A_CardNO, string VC_OC_UserName, string VC_OC_Company, int I_A_CardType, string StartDate, string EndDate, int TotalRecords, int PageIndex) 107 { 108 return Search("", VC_OC_UserName, VC_OC_Company, VC_A_CardNO, I_A_CardType, "", "", "", StartDate, EndDate, TotalRecords, 109 PageIndex); 110 } 111 } 112 }
1 ---------CT_Append_DAL.cs------------------------------------------------------------------ 2 // =================================================================== 3 // Name: CT_Append Data Layers 4 // Author: 小华 5 // DateTime: 2011-07-08 6 // Description: CT_Append.cs 7 // =================================================================== 8 using System; 9 using System.Collections.Generic; 10 using System.Data; 11 using System.Data.SqlClient; 12 using GPOS.Components; 13 using GPOS.Model; 14 using GPOS.IDAL; 15 16 namespace GPOS.DAL 17 { 18 public class CT_Append : ICT_Append 19 { 20 private readonly string connectionString = ForumConfig.ReadConfigInfo().DataBase; 21 22 // <summary> 23 // Create a records 24 // </summary> 25 // <param name="CT_AppendInfo">Model::CT_AppendInfo</param> 26 // <returns></returns> 27 public int Create(CT_AppendInfo _CT_AppendInfo) 28 { 29 int ret = -1; 30 SqlConnection myConnection = new SqlConnection(connectionString); 31 SqlCommand myCommand = new SqlCommand("CT_Append_Create", myConnection); 32 33 myCommand.CommandType = CommandType.StoredProcedure; 34 35 myCommand.Parameters.Add("@VC_A_SNNO", SqlDbType.VarChar, 50).Value = _CT_AppendInfo.VC_A_SNNO; 36 myCommand.Parameters.Add("@VC_A_AppendType", SqlDbType.VarChar, 50).Value = _CT_AppendInfo.VC_A_AppendType; 37 myCommand.Parameters.Add("@VC_A_CardNO", SqlDbType.VarChar, 50).Value = _CT_AppendInfo.VC_A_CardNO; 38 myCommand.Parameters.Add("@I_A_CardType", SqlDbType.Int).Value = _CT_AppendInfo.I_A_CardType; 39 myCommand.Parameters.Add("@I_A_PointToOil", SqlDbType.Int).Value = _CT_AppendInfo.I_A_PointToOil; 40 myCommand.Parameters.Add("@VC_TicketType", SqlDbType.VarChar, 50).Value = _CT_AppendInfo.VC_TicketType; 41 myCommand.Parameters.Add("@VC_TicketNO", SqlDbType.VarChar, 50).Value = _CT_AppendInfo.VC_TicketNO; 42 myCommand.Parameters.Add("@DE_A_BAmount", SqlDbType.Decimal).Value = _CT_AppendInfo.DE_A_BAmount; 43 myCommand.Parameters.Add("@DE_A_AppendAmount", SqlDbType.Decimal).Value = _CT_AppendInfo.DE_A_AppendAmount; 44 myCommand.Parameters.Add("@DE_A_AAmount", SqlDbType.Decimal).Value = _CT_AppendInfo.DE_A_AAmount; 45 myCommand.Parameters.Add("@D_A_AppendDateTime", SqlDbType.DateTime).Value = _CT_AppendInfo.D_A_AppendDateTime; 46 myCommand.Parameters.Add("@VC_A_Remark", SqlDbType.VarChar, 256).Value = _CT_AppendInfo.VC_A_Remark; 47 myCommand.Parameters.Add("@VC_A_OperatorNO", SqlDbType.VarChar, 50).Value = _CT_AppendInfo.VC_A_OperatorNO; 48 49 myConnection.Open(); 50 try 51 { 52 ret = Convert.ToInt32(myCommand.ExecuteScalar()); 53 } 54 catch (Exception ex) 55 { 56 WriteDataErrLog.WriteDataErrDetail(myCommand, ex.ToString()); 57 58 } 59 myConnection.Close(); 60 61 return ret; 62 } 63 64 65 66 // <summary> 67 // Delete a records 68 // </summary> 69 // <param name="vC_A_SNNO">string::vC_A_SNNO</param> 70 // <returns></returns> 71 public int Remove(string vC_A_SNNO) 72 { 73 int ret = -1; 74 SqlConnection myConnection = new SqlConnection(connectionString); 75 SqlCommand myCommand = new SqlCommand("CT_Append_Remove", myConnection); 76 77 myCommand.CommandType = CommandType.StoredProcedure; 78 79 myCommand.Parameters.Add("@VC_A_SNNO", SqlDbType.VarChar).Value = vC_A_SNNO; 80 81 myConnection.Open(); 82 try 83 { 84 ret = Convert.ToInt32(myCommand.ExecuteScalar()); 85 } 86 catch (Exception ex) 87 { 88 WriteDataErrLog.WriteDataErrDetail(myCommand, ex.ToString()); 89 90 } 91 92 myConnection.Close(); 93 94 return ret; 95 } 96 97 // <summary> 98 // Get a records 99 // </summary> 100 // <param name="vC_A_SNNO">string::vC_A_SNNO</param> 101 // <returns></returns> 102 public CT_AppendInfo GetById(string vC_A_SNNO) 103 { 104 SqlConnection myConnection = new SqlConnection(connectionString); 105 SqlCommand myCommand = new SqlCommand("CT_Append_GetByVC_A_SNNO", myConnection); 106 107 myCommand.CommandType = CommandType.StoredProcedure; 108 myCommand.Parameters.Add("@VC_A_SNNO", SqlDbType.VarChar).Value = vC_A_SNNO; 109 110 myConnection.Open(); 111 112 CT_AppendInfo _CT_AppendInfo2 = new CT_AppendInfo(); 113 SqlDataReader dr = myCommand.ExecuteReader(); 114 115 while (dr.Read()) 116 _CT_AppendInfo2 = Populate(dr); 117 118 dr.Close(); 119 myConnection.Close(); 120 121 return _CT_AppendInfo2; 122 } 123 124 125 // <summary> 126 // Get List 127 // </summary> 128 // <param name="TotalRecords">Int::TotalRecords</param> 129 // <param name="PageSize">Int::PageSize</param> 130 // <returns></returns> 131 public PageSetInfo Get(int TotalRecords, int PageIndex) 132 { 133 SqlConnection myConnection = new SqlConnection(connectionString); 134 SqlCommand myCommand = new SqlCommand("CT_Append_Get", myConnection); 135 136 myCommand.CommandType = CommandType.StoredProcedure; 137 138 myCommand.Parameters.Add("@TotalRecords", SqlDbType.Int).Value = TotalRecords; 139 myCommand.Parameters.Add("@PageIndex", SqlDbType.Int).Value = PageIndex; 140 141 myConnection.Open(); 142 143 PageSetInfo _CT_AppendSetInfo = new PageSetInfo(); 144 try 145 { 146 SqlDataReader dr = myCommand.ExecuteReader(); 147 148 while (dr.Read()) 149 _CT_AppendSetInfo.CT_AppendInfo.Add(Populate(dr)); 150 151 dr.NextResult(); 152 153 while (dr.Read()) 154 _CT_AppendSetInfo.TotalRecords = Convert.ToInt32(dr["TotalRecords"]); 155 156 dr.Close(); 157 } 158 catch (Exception ex) 159 { 160 WriteDataErrLog.WriteDataErrDetail(myCommand, ex.ToString()); 161 162 } 163 164 myConnection.Close(); 165 166 return _CT_AppendSetInfo; 167 } 168 169 /// <summary> 170 /// 查询充值记录 171 /// </summary> 172 /// <param name="VC_A_SNNO">充值交易序号</param> 173 /// <param name="VC_OC_UserName">客户名称</param> 174 /// <param name="VC_OC_Company">单位</param> 175 /// <param name="VC_A_CardNO">卡号</param> 176 /// <param name="CardType">卡片类型</param> 177 /// <param name="VC_A_AppendType">充值类型</param> 178 /// <param name="VC_TicketType">发票类型</param> 179 /// <param name="VC_TicketNO">发票编号</param> 180 /// <param name="StartDate">开始日期</param> 181 /// <param name="EndDate">结束日期</param> 182 /// <param name="TotalRecords">每页的条数</param> 183 /// <param name="PageIndex">页数</param> 184 /// <returns></returns> 185 public PageSetInfo Search(string VC_A_SNNO,string VC_OC_UserName,string VC_OC_Company,string VC_A_CardNO,int CardType,string VC_A_AppendType,string VC_TicketType,string VC_TicketNO, string StartDate, string EndDate, int TotalRecords, int PageIndex) 186 { 187 SqlConnection myConnection = new SqlConnection(connectionString); 188 SqlCommand myCommand = new SqlCommand("CT_Append_Search", myConnection); 189 190 myCommand.CommandType = CommandType.StoredProcedure; 191 192 myCommand.Parameters.Add("@VC_A_SNNO", SqlDbType.VarChar).Value = VC_A_SNNO; 193 myCommand.Parameters.Add("@VC_OC_UserName", SqlDbType.VarChar).Value = VC_OC_UserName; 194 myCommand.Parameters.Add("@VC_OC_Company", SqlDbType.VarChar).Value = VC_OC_Company; 195 myCommand.Parameters.Add("@VC_A_CardNO", SqlDbType.VarChar).Value = VC_A_CardNO; 196 myCommand.Parameters.Add("@CardType", SqlDbType.Int).Value = CardType; 197 myCommand.Parameters.Add("@VC_A_AppendType", SqlDbType.VarChar).Value = VC_A_AppendType; 198 myCommand.Parameters.Add("@VC_TicketType", SqlDbType.VarChar).Value = VC_TicketType; 199 myCommand.Parameters.Add("@VC_TicketNO", SqlDbType.VarChar).Value = VC_TicketNO; 200 myCommand.Parameters.Add("@StartDate", SqlDbType.VarChar).Value = StartDate; 201 myCommand.Parameters.Add("@EndDate", SqlDbType.VarChar).Value = EndDate; 202 myCommand.Parameters.Add("@TotalRecords", SqlDbType.Int).Value = TotalRecords; 203 myCommand.Parameters.Add("@PageIndex", SqlDbType.Int).Value = PageIndex; 204 205 myConnection.Open(); 206 PageSetInfo _CT_AppendSetInfo = new PageSetInfo(); 207 try 208 { 209 SqlDataReader dr = myCommand.ExecuteReader(); 210 211 while (dr.Read()) 212 _CT_AppendSetInfo.CT_AppendInfo.Add(Populate(dr)); 213 214 dr.NextResult(); 215 216 while (dr.Read()) 217 _CT_AppendSetInfo.TotalRecords = Convert.ToInt32(dr["TotalRecords"]); 218 219 dr.Close(); 220 } 221 catch (Exception ex) 222 { 223 WriteDataErrLog.WriteDataErrDetail(myCommand, ex.ToString()); 224 225 } 226 227 myConnection.Close(); 228 229 return _CT_AppendSetInfo; 230 } 231 232 233 234 private CT_AppendInfo Populate(SqlDataReader dr) 235 { 236 CT_AppendInfo _CT_AppendInfo = new CT_AppendInfo(); 237 238 _CT_AppendInfo.VC_A_SNNO = Convert.ToString(dr["VC_A_SNNO"]); 239 _CT_AppendInfo.VC_A_AppendType = Convert.ToString(dr["VC_A_AppendType"]); 240 _CT_AppendInfo.VC_A_CardNO = Convert.ToString(dr["VC_A_CardNO"]); 241 _CT_AppendInfo.I_A_CardType = Convert.ToInt32(dr["I_A_CardType"]); 242 _CT_AppendInfo.I_A_CardTypeName = Filter.CardTypeToStr(_CT_AppendInfo.I_A_CardType); 243 _CT_AppendInfo.I_A_PointToOil = Convert.ToInt32(dr["I_A_PointToOil"]); 244 _CT_AppendInfo.VC_TicketType = Convert.ToString(dr["VC_TicketType"]); 245 _CT_AppendInfo.VC_TicketNO = Convert.ToString(dr["VC_TicketNO"]); 246 _CT_AppendInfo.DE_A_BAmount = Convert.ToDecimal(dr["DE_A_BAmount"]); 247 _CT_AppendInfo.DE_A_AppendAmount = Convert.ToDecimal(dr["DE_A_AppendAmount"]); 248 _CT_AppendInfo.DE_A_AAmount = Convert.ToDecimal(dr["DE_A_AAmount"]); 249 _CT_AppendInfo.D_A_AppendDateTime = Convert.ToDateTime(dr["D_A_AppendDateTime"]); 250 _CT_AppendInfo.VC_A_Remark = Convert.ToString(dr["VC_A_Remark"]); 251 _CT_AppendInfo.VC_A_OperatorNO = Convert.ToString(dr["VC_A_OperatorNO"]); 252 253 return _CT_AppendInfo; 254 } 255 } 256 }
1 -----------ICT_Append_IDAL.cs--------------------------------------------------------------- 2 // =================================================================== 3 // Name: The Interface of CT_Append 4 // Author: 小华 5 // DateTime: 2011-07-08 6 // Description: ICT_Append.cs 7 // =================================================================== 8 using System; 9 using System.Collections.Generic; 10 using GPOS.Model; 11 12 namespace GPOS.IDAL 13 { 14 public interface ICT_Append 15 { 16 int Create(CT_AppendInfo _CT_AppendInfo); 17 int Remove(string vC_A_SNNO); 18 CT_AppendInfo GetById(string vC_A_SNNO); 19 PageSetInfo Get(int TotalRecords, int PageIndex); 20 21 PageSetInfo Search(string VC_A_SNNO, string VC_OC_UserName, string VC_OC_Company, string VC_A_CardNO, int CardType, 22 string VC_A_AppendType, string VC_TicketType, string VC_TicketNO, string StartDate, 23 string EndDate, int TotalRecords, int PageIndex); 24 } 25 }
1 ------CT_AppendInfo.cs-------------------------------------------------------------------- 2 // =================================================================== 3 // Name: The Model of CT_Append 4 // Author: 小华 5 // DateTime: 2011-07-08 6 // Description: CT_AppendInfo.cs 7 // =================================================================== 8 9 using System; 10 using System.Collections.Generic; 11 using System.Linq; 12 using System.Text; 13 14 namespace GPOS.Model 15 { 16 [Serializable] 17 public class CT_AppendInfo 18 { 19 #region Variable definitions 20 private int _recordNO; 21 private string _vC_A_SNNO; 22 private string _vC_A_AppendType = String.Empty; 23 private string _vC_A_CardNO = String.Empty; 24 private int _i_A_CardType; 25 private string _I_A_CardTypeName; 26 private int _i_A_PointToOil; 27 private string _vC_TicketType = String.Empty; 28 private string _vC_TicketNO = String.Empty; 29 private decimal _dE_A_BAmount; 30 private decimal _dE_A_AppendAmount; 31 private decimal _dE_A_AAmount; 32 private DateTime _d_A_AppendDateTime; 33 private string _vC_A_Remark = String.Empty; 34 private string _vC_A_OperatorNO = String.Empty; 35 #endregion 36 37 #region Public Properties 38 ///<summary> 39 ///记录编号 40 ///</summary> 41 public int RecordNO 42 { 43 get { return _recordNO; } 44 set { _recordNO = value; } 45 } 46 47 ///<summary> 48 ///充值交易序号 49 ///</summary> 50 public string VC_A_SNNO 51 { 52 get { return _vC_A_SNNO; } 53 set { _vC_A_SNNO = value; } 54 } 55 56 ///<summary> 57 ///充值类型 58 ///</summary> 59 public string VC_A_AppendType 60 { 61 get { return _vC_A_AppendType; } 62 set { _vC_A_AppendType = value; } 63 } 64 65 ///<summary> 66 ///充值卡号 67 ///</summary> 68 public string VC_A_CardNO 69 { 70 get { return _vC_A_CardNO; } 71 set { _vC_A_CardNO = value; } 72 } 73 74 ///<summary> 75 ///卡片类型 76 ///</summary> 77 public int I_A_CardType 78 { 79 get { return _i_A_CardType; } 80 set { _i_A_CardType = value; } 81 } 82 83 ///<summary> 84 ///卡片类型名称 85 ///</summary> 86 public string I_A_CardTypeName 87 { 88 get { return _I_A_CardTypeName; } 89 set { _I_A_CardTypeName = value; } 90 } 91 92 ///<summary> 93 ///积分/优惠兑换数量 94 ///</summary> 95 public int I_A_PointToOil 96 { 97 get { return _i_A_PointToOil; } 98 set { _i_A_PointToOil = value; } 99 } 100 101 ///<summary> 102 ///票据类型 103 ///</summary> 104 public string VC_TicketType 105 { 106 get { return _vC_TicketType; } 107 set { _vC_TicketType = value; } 108 } 109 110 ///<summary> 111 ///票据编号 112 ///</summary> 113 public string VC_TicketNO 114 { 115 get { return _vC_TicketNO; } 116 set { _vC_TicketNO = value; } 117 } 118 119 ///<summary> 120 ///充值前余额 121 ///</summary> 122 public decimal DE_A_BAmount 123 { 124 get { return _dE_A_BAmount; } 125 set { _dE_A_BAmount = value; } 126 } 127 128 ///<summary> 129 ///充值金额 130 ///</summary> 131 public decimal DE_A_AppendAmount 132 { 133 get { return _dE_A_AppendAmount; } 134 set { _dE_A_AppendAmount = value; } 135 } 136 137 ///<summary> 138 ///充值后余额 139 ///</summary> 140 public decimal DE_A_AAmount 141 { 142 get { return _dE_A_AAmount; } 143 set { _dE_A_AAmount = value; } 144 } 145 146 ///<summary> 147 ///充值时间 148 ///</summary> 149 public DateTime D_A_AppendDateTime 150 { 151 get { return _d_A_AppendDateTime; } 152 set { _d_A_AppendDateTime = value; } 153 } 154 155 ///<summary> 156 ///备注 157 ///</summary> 158 public string VC_A_Remark 159 { 160 get { return _vC_A_Remark; } 161 set { _vC_A_Remark = value; } 162 } 163 164 ///<summary> 165 ///操作员物理卡号 166 ///</summary> 167 public string VC_A_OperatorNO 168 { 169 get { return _vC_A_OperatorNO; } 170 set { _vC_A_OperatorNO = value; } 171 } 172 #endregion 173 174 #region Constructor function 175 176 public CT_AppendInfo() 177 { 178 } 179 180 public CT_AppendInfo 181 ( 182 int recordNO, 183 string vC_A_SNNO, 184 string vC_A_AppendType, 185 string vC_A_CardNO, 186 int i_A_CardType, 187 int i_A_PointToOil, 188 string vC_TicketType, 189 string vC_TicketNO, 190 decimal dE_A_BAmount, 191 decimal dE_A_AppendAmount, 192 decimal dE_A_AAmount, 193 DateTime d_A_AppendDateTime, 194 string vC_A_Remark, 195 string vC_A_OperatorNO 196 ) 197 { 198 _recordNO = recordNO; 199 _vC_A_SNNO = vC_A_SNNO; 200 _vC_A_AppendType = vC_A_AppendType; 201 _vC_A_CardNO = vC_A_CardNO; 202 _i_A_CardType = i_A_CardType; 203 _i_A_PointToOil = i_A_PointToOil; 204 _vC_TicketType = vC_TicketType; 205 _vC_TicketNO = vC_TicketNO; 206 _dE_A_BAmount = dE_A_BAmount; 207 _dE_A_AppendAmount = dE_A_AppendAmount; 208 _dE_A_AAmount = dE_A_AAmount; 209 _d_A_AppendDateTime = d_A_AppendDateTime; 210 _vC_A_Remark = vC_A_Remark; 211 _vC_A_OperatorNO = vC_A_OperatorNO; 212 213 } 214 #endregion 215 216 } 217 }
就这麽多了
需要数据库文件的可以Q我:1815357042
如果要写132个模板,那你还用codesmith做什么,手写算啦
BLL IDAL DAL MODEL
根据各个项目的共性一个项目写一个模板就OK啦,实际上你要做的只是遍历数据库的表结构,然后根据表结构自动生成相关的类而已。
我也知道遍历数据库里的表,每层都是bll idal dal model ,但是就是不知道怎麽写,所以想请教大家
@桦仔:
<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context" Description="Table that the object is based on." %>
在你的模板里加入这么一行,你就可以在模板里访问数据表的结构了,你可以看看SchemaExplorer.TableSchema里都有些什么属性。
@狼Robot:
在model模板文件里面已经加了这一句
<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Optional="True" Category="db" Description="表映射文件" %>
请问狼robot大侠能辅导一下我吗,小弟不胜感激,小弟QQ:1815357042
@桦仔:
加了这句代码后,你后面的代码中就可以用
<%%>这样的代码块来写C#代码了。
比如:
<% foreach(ColumnSchema col in SourceTable.Columns){ } %>
这样就可以遍历表的所有字段了,具体的内容你可以看一下相关类的属性。
@狼Robot:
还是想大侠详细一点
@桦仔:
其实你只需要BLL IDAL DAL MODEL各一个模板,找出各个类中的规律,通过遍历表结构生成对应的类就可以了。
比如MODEL类,实际上就是类似下面的代码生成的:
public class <%=SourceTable.Name%>{
<% foreach(ColumnSchema col in SourceTable.Columns){%>
public <%=col.SystemType%> <%=col.Name%>{get;set;}
<%}%>
}