<%--
Name:
Author:
Description:
--%>
<%@ CodeTemplate Language="C#" ResponseEncoding="UTF-8" TargetLanguage="Text" Src="" Debug="False" Description="Template description here." %>
<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context" Description="请选择数据表!" %>
<%@ Property Name="NameSpace" Type="System.String" Default="" Optional="False" Category="Description" Description="请输入命名空间" %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Import Namespace="SchemaExplorer" %>
/*************************************************************/
/* CodeSmith模板生成数据接口 */
/*************************************************************/
using System;
using System.Data;
using System.Collections.Generic;
namespace <%=NameSpace%>.IDAL
{
public interface I<%=SourceTable.Name%>
{
void Add(<%=NameSpace + ".Model." + SourceTable.Name%> model);
void Update(<%=NameSpace + ".Model." + SourceTable.Name%> model);
void Delete(<%=GetPrimaryKeyType(SourceTable) + " " + GetPrimaryKeyName(SourceTable)%>);
List<<%=NameSpace + ".Model." + SourceTable.Name%>> GetList(string strWhere);
DataSet GetData(string strWhere);
<%=NameSpace + ".Model." + SourceTable.Name%> GetModel(<%=GetPrimaryKeyType(SourceTable) + " " + GetPrimaryKeyName(SourceTable)%>);
}
}
<script runat="template">
public string GetPrimaryKeyName(TableSchema table)
{
string primaryKeyName = "";
for(int i=0; i<table.Columns.Count; i++)
{
if(table.Columns[i].IsPrimaryKeyMember)
primaryKeyName = table.Columns[i].Name;
}
return primaryKeyName.ToLower();
}
public string GetPrimaryKeyType(TableSchema table)
{
int temp = 0;
for(int i=0; i<table.Columns.Count; i++)
{
if(table.Columns[i].IsPrimaryKeyMember)
temp = i;
}
string para = "";
if (table.Columns[temp].Name.EndsWith("TypeCode"))
return table.Columns[temp].Name;
switch (table.Columns[temp].DataType)
{
case DbType.AnsiString:
para = "string";
break;
case DbType.AnsiStringFixedLength:
para = "string";
break;
case DbType.Binary:
para = "byte[]";
break;
case DbType.Boolean:
para = "bool";
break;
case DbType.Byte:
para = "int";
break;
case DbType.Currency:
para = "decimal";
break;
case DbType.Date:
para = "DateTime";
break;
case DbType.DateTime:
para = "DateTime";
break;
case DbType.Decimal:
para = "decimal";
break;
case DbType.Double:
para = "double";
break;
case DbType.Guid:
para = "Guid";
break;
case DbType.Int16:
para = "short";
break;
case DbType.Int32:
para = "int";
break;
case DbType.Int64:
para = "long";
break;
case DbType.Object:
para = "object";
break;
case DbType.SByte:
para = "sbyte";
break;
case DbType.Single:
para = "float";
break;
case DbType.String:
para = "string";
break;
case DbType.StringFixedLength:
para = "string";
break;
case DbType.Time:
para = "TimeSpan";
break;
case DbType.UInt16:
para = "ushort";
break;
case DbType.UInt32:
para = "uint";
break;
case DbType.UInt64:
para = "ulong";
break;
case DbType.VarNumeric:
para = "decimal";
break;
default:
para = "__UNKNOWN__" + table.Columns[temp].NativeType;
break;
}
return para;
}
</script>