第一個文件是businessobjctforVIEw.cst,生成C#實體類,此腳本需要引用第二個文件CommonUtility.cs。需將兩個文件放在同一目錄中。
< Description="Generatesaupdatestoredprocedure."%>
<%@AssemblyName="SchemaExplorer"%>
<%@ImportNamespace="SchemaExplorer"%>
< Category="Context"
Description="Tablethatthestoredproceduresshouldbebasedon."%>
<%@AssemblySrc="CommonUtility.cs"%>
<%@ImportNamespace="Common.Data"%>
<scriptrunat="template">
CommonUtilityrule=newCommonUtility();
</script>
usingSystem;
usingSystem.Collections;
usingSystem.Collections.Generic;
usingSystem.Data;
namespaceSOA.Model
{
///<summary>
///<%=SourceTable.Name%>objectforVIEwtable'<%=SourceTable.Name%>'.
///</summary>
[Serializable]
publicclass<%=SourceTable.Name%>
{
#regionPrivateMember
<%for(inti=0;i<SourceTable.Columns.Count;i++){%>
private<%=rule.GetCSharpVariableType(SourceTable.Columns[i])%>_<%=SourceTable.Columns[i].Name%>;
<%}%>
#endregion
#regionConstructor
public<%=SourceTable.Name%>(){}
public<%=SourceTable.Name%>(
<%for(inti=0;i<SourceTable.Columns.Count-1;i++){%>
<%=rule.GetCSharpVariableType(SourceTable.Columns[i])%><%=SourceTable.Columns[i].Name%>,
<%}%>
<%=rule.GetCSharpVariableType(SourceTable.Columns[SourceTable.Columns.Count-1])%><%=SourceTable.Columns[SourceTable.Columns.Count-1].Name%>
)
{
<%for(inti=0;i<SourceTable.Columns.Count;i++){%>
_<%=SourceTable.Columns[i].Name%>=<%=SourceTable.Columns[i].Name%>;
<%}%>
}
#endregion
#regionPublicPropertIEs
<%for(inti=0;i<SourceTable.Columns.Count;i++){%>
public<%=rule.GetCSharpVariableType(SourceTable.Columns[i])%><%=rule.GetCamelCaseName(SourceTable.Columns[i].Name)%>
{
get{return_<%=SourceTable.Columns[i].Name%>;}
set{_<%=SourceTable.Columns[i].Name%>=value;}
}
<%}%>
#endregion
}
}
第二個文件是CommonUtility.cs,此文件是包含C#的數據類型定義以及輸出:
usingSystem;
usingSystem.Text;
usingCodeSmith.Engine;
usingSchemaExplorer;
usingSystem.ComponentModel;
usingSystem.Data;
namespaceCommon.Data
{
/**////<summary>
///TemplateRule
///</summary>
publicclassCommonUtility
{
//getColumnsinfobyTableName
publicViewColumnScheMacollectionGetColumnCollectionByTable(VIEwSchematable)
{
ViewColumnScheMacollectioncolumns=newVIEwColumnScheMacollection(table.Columns);
returncolumns;
}
//Getcamelcasename,suchasCustomer,
publicstringGetCamelCaseName(stringstr)
{
returnstr.Substring(0,1).ToUpper()+str.Substring(1);
}
//Get,user,privateconstStringUSER_FIELD="User"
publicstringGetMemberConstantDeclarationStatement(ColumnScheMacolumn)
{
returnGetMemberConstantDeclarationStatement("publicconstString",column);
}
//suchASPublicconstStringUSER_TABLE="User"
publicstringGetTableConstantDeclarationStatement(VIEwSchematable)
{
returnGetMemberConstantDeclarationStatement("publicconstString",table);
}
//suckasUSER_TABLE
publicstringGetUpperStatement(VIEwSchematable)
{
return table.Name.ToUpper()+"_TABLE";
}
//suckasUSER_FIELD
publicstringGetUpperStatement(ColumnScheMacolumn)
{
returncolumn.Name.ToUpper()+"_FIELD";
}
//suchasUSER_TABLE="User"
publicstringGetMemberConstantDeclarationStatement(stringprotectionLevel,VIEwSchematable)
{
returnprotectionLevel+GetUpperStatement(table)+"="+GetCamelCaseName(table.Name)+"";
}
//suchasUSERID_FIELD="Userid"
publicstringGetMemberConstantDeclarationStatement(stringprotectionLevel,ColumnScheMacolumn)
{
returnprotectionLevel+GetUpperStatement(column)+"="+GetCamelCaseName(column.Name)+"";
}
publicstringGetCSharpVariableType(VIEwColumnScheMacolumn)
{
switch(column.DataType)
{
caseDbType.AnsiString:return"string";
caseDbType.AnsiStringFixedLength:return"string";
caseDbType.Binary:return"byte[]";
caseDbType.Boolean:return"bool";
caseDbType.Byte:return"int";
caseDbType.Currency:return"decimal";