生成数据表的映射文件 for iBATIS.NET
Filename: MappingFile.cst
<%--
Code Generator for iBATIS.NET 1.2.1
功能描述: 生成数据表的映射文件
--%>
<%@ CodeTemplate Language="C#" TargetLanguage="C#" LinePragmas="True" %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Import Namespace="SchemaExplorer" %>
<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="DataSource"
Description="选择一个数据表" %>
<%@ Property Name="TableRename" Type="String" Category="DataSource"
Description="如果不需要表名到类名的重命名, 请保留空" %>
<%@ Property Name="Assemble" Type="String" Category="Main"
Description="程序集名称" %>
<%@ Property Name="Namespace" Type="String" Category="Main"
Description="类所在的命名空间" %>
<%@ Property Name="DeveloperName" Type="String" Category="Main"
Description="作者" %>
<?xml version="1.0" encoding="utf-8" ?>
<sqlMap
namespace="<%= ClassName %>"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="SqlMap.xsd">
<!--
Created: <%= DateTime.Now.ToShortDateString() %> Author: <%= DeveloperName %>
File: <%= ClassName %>.xml
Description: 数据表 <%= TableName %> 的映射文件, 使用 CodeSmith 自动生成.
-->
<alias>
<typeAlias alias="<%= ClassName %>" type="<%= Namespace %>.<%= ClassName %>, <%= Assemble %>" />
</alias>
<!-- 返回结果的类属性与数据库字段映射 -->
<resultMaps>
<resultMap id="SelectResult" class="<%= ClassName %>">
<%= GetResultProperty() %>
</resultMap>
</resultMaps>
<!-- 数据库操作定义块 -->
<statements>
<select id="selectAll" parameterClass="string" resultMap="SelectResult">
select *
from [<%= TableName %>]
</select>
<select id="select" parameterClass="string" resultMap="SelectResult">
select *
from [<%= TableName %>]
where <%= GetPrimaryKey() %>=#value#
</select>
<insert id="insert" parameterClass="<%= TableRename %>" resultClass="int">
insert into [<%= TableName %>]
(<%= GetInsertColumnList(false) %>)
values
(<%= GetInsertColumnList(true) %>)
<selectKey resultClass="int" type="post" property="<%= GetPrimaryKey() %>">
select @@IDENTITY as value
</selectKey>
</insert>
<update id="update" parameterClass="<%= TableRename %>" resultClass="int">
update [<%= TableName %>]
set <%= GetUpdateColumnList() %>
where <%= GetPrimaryKey() %>=#<%= GetPrimaryKey() %>#
<selectKey resultClass="int" type="post">
select @@RouCount as value
</selectKey>
</update>
<delete id="delete" parameterClass="string" resultClass="int">
delete [<%= TableName %>]
where <%= GetPrimaryKey() %>=#value#
<selectKey resultClass="int" type="post">
select @@RouCount as value
</selectKey>
</delete>
</statements>
</sqlMap>
<script runat="template">
/// <summary>
/// 输出的类名
/// </summary>
private string ClassName
{
get
{
return TableRename.Trim().Length == 0 ? "SourceTable.Name" : TableRename.Trim();
}
}
/// <summary>
/// 输入的数据表名
/// </summary>
private string TableName
{
get
{
return SourceTable.Name;
}
}
private string GetResultProperty()
{
string outString = string.Empty;
for (int i=0; i<SourceTable.Columns.Count; i++)
{
string colName = SourceTable.Columns[i].Name.ToString();
outString += string.Format("\t\t\t<result property=\"{0}\" column=\"{0}\" />", colName);
outString += (i == SourceTable.Columns.Count-1) ? "" : "\r\n";
}
return outString;
}
private string GetInsertColumnList(bool isValue)
{
string outString = string.Empty;
for (int i=0; i<SourceTable.Columns.Count; i++)
{
if( SourceTable.Columns[i].IsPrimaryKeyMember ) continue;
string colName = SourceTable.Columns[i].Name.ToString();
if( isValue )
{
outString += "#" + colName + "#";
}
else
{
outString += "[" + colName + "]";
}
outString += (i == SourceTable.Columns.Count-1) ? "" : ", ";
}
return outString;
}
private string GetUpdateColumnList()
{
string outString = string.Empty;
for (int i=0; i<SourceTable.Columns.Count; i++)
{
if( SourceTable.Columns[i].IsPrimaryKeyMember ) continue;
string colName = SourceTable.Columns[i].Name.ToString();
outString += string.Format("[{0}]=#{0}#", colName);
outString += (i == SourceTable.Columns.Count-1) ? "" : ",\r\n\t\t\t\t";
}
return outString;
}
private string GetPrimaryKey()
{
string outString = string.Empty;
for (int i=0; i<SourceTable.Columns.Count; i++)
{
if( SourceTable.Columns[i].IsPrimaryKeyMember )
{
outString = SourceTable.Columns[i].Name;
break;
}
}
return outString;
}
</script>
Code Generator for iBATIS.NET 1.2.1
功能描述: 生成数据表的映射文件
--%>
<%@ CodeTemplate Language="C#" TargetLanguage="C#" LinePragmas="True" %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Import Namespace="SchemaExplorer" %>
<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="DataSource"
Description="选择一个数据表" %>
<%@ Property Name="TableRename" Type="String" Category="DataSource"
Description="如果不需要表名到类名的重命名, 请保留空" %>
<%@ Property Name="Assemble" Type="String" Category="Main"
Description="程序集名称" %>
<%@ Property Name="Namespace" Type="String" Category="Main"
Description="类所在的命名空间" %>
<%@ Property Name="DeveloperName" Type="String" Category="Main"
Description="作者" %>
<?xml version="1.0" encoding="utf-8" ?>
<sqlMap
namespace="<%= ClassName %>"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="SqlMap.xsd">
<!--
Created: <%= DateTime.Now.ToShortDateString() %> Author: <%= DeveloperName %>
File: <%= ClassName %>.xml
Description: 数据表 <%= TableName %> 的映射文件, 使用 CodeSmith 自动生成.
-->
<alias>
<typeAlias alias="<%= ClassName %>" type="<%= Namespace %>.<%= ClassName %>, <%= Assemble %>" />
</alias>
<!-- 返回结果的类属性与数据库字段映射 -->
<resultMaps>
<resultMap id="SelectResult" class="<%= ClassName %>">
<%= GetResultProperty() %>
</resultMap>
</resultMaps>
<!-- 数据库操作定义块 -->
<statements>
<select id="selectAll" parameterClass="string" resultMap="SelectResult">
select *
from [<%= TableName %>]
</select>
<select id="select" parameterClass="string" resultMap="SelectResult">
select *
from [<%= TableName %>]
where <%= GetPrimaryKey() %>=#value#
</select>
<insert id="insert" parameterClass="<%= TableRename %>" resultClass="int">
insert into [<%= TableName %>]
(<%= GetInsertColumnList(false) %>)
values
(<%= GetInsertColumnList(true) %>)
<selectKey resultClass="int" type="post" property="<%= GetPrimaryKey() %>">
select @@IDENTITY as value
</selectKey>
</insert>
<update id="update" parameterClass="<%= TableRename %>" resultClass="int">
update [<%= TableName %>]
set <%= GetUpdateColumnList() %>
where <%= GetPrimaryKey() %>=#<%= GetPrimaryKey() %>#
<selectKey resultClass="int" type="post">
select @@RouCount as value
</selectKey>
</update>
<delete id="delete" parameterClass="string" resultClass="int">
delete [<%= TableName %>]
where <%= GetPrimaryKey() %>=#value#
<selectKey resultClass="int" type="post">
select @@RouCount as value
</selectKey>
</delete>
</statements>
</sqlMap>
<script runat="template">
/// <summary>
/// 输出的类名
/// </summary>
private string ClassName
{
get
{
return TableRename.Trim().Length == 0 ? "SourceTable.Name" : TableRename.Trim();
}
}
/// <summary>
/// 输入的数据表名
/// </summary>
private string TableName
{
get
{
return SourceTable.Name;
}
}
private string GetResultProperty()
{
string outString = string.Empty;
for (int i=0; i<SourceTable.Columns.Count; i++)
{
string colName = SourceTable.Columns[i].Name.ToString();
outString += string.Format("\t\t\t<result property=\"{0}\" column=\"{0}\" />", colName);
outString += (i == SourceTable.Columns.Count-1) ? "" : "\r\n";
}
return outString;
}
private string GetInsertColumnList(bool isValue)
{
string outString = string.Empty;
for (int i=0; i<SourceTable.Columns.Count; i++)
{
if( SourceTable.Columns[i].IsPrimaryKeyMember ) continue;
string colName = SourceTable.Columns[i].Name.ToString();
if( isValue )
{
outString += "#" + colName + "#";
}
else
{
outString += "[" + colName + "]";
}
outString += (i == SourceTable.Columns.Count-1) ? "" : ", ";
}
return outString;
}
private string GetUpdateColumnList()
{
string outString = string.Empty;
for (int i=0; i<SourceTable.Columns.Count; i++)
{
if( SourceTable.Columns[i].IsPrimaryKeyMember ) continue;
string colName = SourceTable.Columns[i].Name.ToString();
outString += string.Format("[{0}]=#{0}#", colName);
outString += (i == SourceTable.Columns.Count-1) ? "" : ",\r\n\t\t\t\t";
}
return outString;
}
private string GetPrimaryKey()
{
string outString = string.Empty;
for (int i=0; i<SourceTable.Columns.Count; i++)
{
if( SourceTable.Columns[i].IsPrimaryKeyMember )
{
outString = SourceTable.Columns[i].Name;
break;
}
}
return outString;
}
</script>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现