ASP.NET三层架构源码(CodeSmith版)之二:Table-IDAL层(数据访问抽象层)
动软代码生成器生成的ASP.NET三层架构代码比较规范,是学习ASP.NET的好例子
此三层架构改造自动软的工厂模式模板,使用CodeSmith进行重写,以方便大家修改模板文件
以下是针对表格的IDAL层源码:
<%@ CodeTemplate Language="C#" TargetLanguage="C#" Description="Generates a class including a special informational header" %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Import Namespace="SchemaExplorer" %>
<%@ Import Namespace="System.Text" %>
<%@ Property Name="Namespace" Type="String" Category="Context" Description="The namespace to use for this class" Default="Crs811NameSpace"%>
<%@ Property Name="Author" Type="String" Category="Context" Description="Author" Default="chenr"%>
<%@ Property Name="TablePrefix" Type="System.String" Default="T" Category="Context" Description="The prefix to remove from table names" %>
<%@ Property Name="TableName" Type="TableSchema" DeepLoad="True" Optional="False" Category="01. Getting Started - Required" Description="" %>
/*------------------------------------------------
// File Name:I<%=ClearPrefix(TableName.Name) %>.cs
// File Description:<%=ClearPrefix(TableName.Name) %> Interface
// Author:<%=Author%>
// Create Time:<%= DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")%>
//------------------------------------------------*/
using System;
using System.Text;
using System.Collections.Generic;
using System.Data;
using <%=Namespace%>.Model;
namespace <%=Namespace%>.IDAL
{
///
/// <%=ClearPrefix(TableName.Name) %> Interface
///
public interface I<%=ClearPrefix(TableName.Name) %>
{
#region 成员方法
///
/// 得到最大ID
///
int GetMaxId();
///
/// 是否存在该记录
///
bool Exists(<%= GetInParameter(TableName) %>);
///
/// 增加一条数据
///
bool Add(m<%=ClearPrefix(TableName.Name) %> model);
///
/// 更新一条数据
///
bool Update(m<%=ClearPrefix(TableName.Name) %> model);
///
/// 删除一条数据
///
bool Delete(<%= GetInParameter(TableName) %>);
<% if (TableName.PrimaryKey.MemberColumns.Count == 1) {%>
bool DeleteList(string <%=TableName.PrimaryKey.MemberColumns[0].Name%>list);
<%}%>
///
/// 得到一个对象实体
///
m<%=ClearPrefix(TableName.Name) %> GetModel(<%= GetInParameter(TableName) %>);
m<%=ClearPrefix(TableName.Name) %> DataRowToModel(DataRow row);
///
/// 获得数据列表
///
DataSet GetList(string strWhere);
///
/// 获得前几行数据
///
DataSet GetList(int Top,string strWhere,string filedOrder);
int GetRecordCount(string strWhere);
DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex);
///
/// 根据分页获得数据列表
///
//DataSet GetList(int PageSize,int PageIndex,string strWhere);
#endregion 成员方法
#region MethodEx
#endregion MethodEx
}
}