针对RapTier模板的一点扩充[将Dt导入成自定义的Model,只需要把外部生成的DataTable进行一次映射即可.附源码]
我看了一下模板,不是很难,由于本人用的是C#.因此模板是为C#转化的:
<%@ Page Language="C#" %>
<%@ Import Namespace="RapidTier.DbSchema" %>
<%
ProjectSetting setting = (ProjectSetting)(this.Context.Items["Setting"]);
DbTable table = (DbTable)(this.Context.Items["Table"]);
DbTableColumns avaColumns = table.AvailableColumns;
int avaColsCount = avaColumns.Count;
DbTableColumns wrtColumns = table.WritableColumns;
int wrtColsCount = wrtColumns.Count;
DbTableColumns updtParamColumns = table.UpdateParamColumns;
int updtParamColsCount = updtParamColumns.Count;
DbTableColumns PKColumns = table.PrimaryKeyColumns;
int PKColsCount = PKColumns.Count;
%>using System;
using System.Data;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using <%= setting.RootNamespace %>.<%= setting.BELNamespace %>;
namespace <%= setting.RootNamespace %>.<%= setting.DALNamespace %>
{
public class <%= setting.GetDALClassName(table) %>
{<%
if (table.GenerateSelectAllSP)
{%>
public DataTable <%= setting.SelectAllSPName %> ()
{
try {
DataSet ds = SqlHelper.ExecuteDataset(DALConfig.ConnectionString, CommandType.StoredProcedure, "<%= setting.GetSelectAllSPName(table) %>");
ds.Tables[0].TableName = "<%= table.Name %>";
return ds.Tables[0];
}
catch (Exception exc)
{
throw exc;
}
}
<%
}
if (table.GenerateSelectAllSP)
{%>
/// <summary>
/// Convert a DataTable To Mapping The Right Object
/// </summary>
/// <param name="dt">DataTable</param>
/// <returns><%= setting.GetBELClassName(table) %> mod</returns>
public <%= setting.GetBELClassName(table) %> ConvertTheDtToObject (DataTable dt)
{
try {
<%= setting.GetBELClassName(table) %> mod = new <%= setting.GetBELClassName(table) %> ();
AutoGenerate Mapping Fields By XuXiaoJun 2005/04/10
<%@ Import Namespace="RapidTier.DbSchema" %>
<%
ProjectSetting setting = (ProjectSetting)(this.Context.Items["Setting"]);
DbTable table = (DbTable)(this.Context.Items["Table"]);
DbTableColumns avaColumns = table.AvailableColumns;
int avaColsCount = avaColumns.Count;
DbTableColumns wrtColumns = table.WritableColumns;
int wrtColsCount = wrtColumns.Count;
DbTableColumns updtParamColumns = table.UpdateParamColumns;
int updtParamColsCount = updtParamColumns.Count;
DbTableColumns PKColumns = table.PrimaryKeyColumns;
int PKColsCount = PKColumns.Count;
%>using System;
using System.Data;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using <%= setting.RootNamespace %>.<%= setting.BELNamespace %>;
namespace <%= setting.RootNamespace %>.<%= setting.DALNamespace %>
{
public class <%= setting.GetDALClassName(table) %>
{<%
if (table.GenerateSelectAllSP)
{%>
public DataTable <%= setting.SelectAllSPName %> ()
{
try {
DataSet ds = SqlHelper.ExecuteDataset(DALConfig.ConnectionString, CommandType.StoredProcedure, "<%= setting.GetSelectAllSPName(table) %>");
ds.Tables[0].TableName = "<%= table.Name %>";
return ds.Tables[0];
}
catch (Exception exc)
{
throw exc;
}
}
<%
}
if (table.GenerateSelectAllSP)
{%>
/// <summary>
/// Convert a DataTable To Mapping The Right Object
/// </summary>
/// <param name="dt">DataTable</param>
/// <returns><%= setting.GetBELClassName(table) %> mod</returns>
public <%= setting.GetBELClassName(table) %> ConvertTheDtToObject (DataTable dt)
{
try {
<%= setting.GetBELClassName(table) %> mod = new <%= setting.GetBELClassName(table) %> ();
AutoGenerate Mapping Fields By XuXiaoJun 2005/04/10
本文来自博客园,作者:Slashout,转载请注明原文链接:https://www.cnblogs.com/SlashOut/archive/2005/04/11/135275.html