<%@ CodeTemplate Language="C#" TargetLanguage="C#"
Description="" %> <%@ Assembly
Name="SchemaExplorer" %> <%@ Assembly
Name="CodeSmith.CustomProperties"%> <%@ Import
Namespace="SchemaExplorer" %> <%@ Property
Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context"
Description="" %> <%@ Property Name="NameSpace"
Type="String" Category="Context" Description="" %>
<script runat="template"> public
string GetMemberAndAtt(ColumnSchema column) { string
Mem="private "; string Att="public ";
if(((bool)column.ExtendedProperties["CS_IsIdentity"].Value)!=true&&column.Name.EndsWith("Id")) {
Mem+=column.Name.Substring(0,column.Name.Length-2)+"
_"+column.Name.Substring(0,column.Name.Length-2)+";\n\n";
Att+=column.Name.Substring(0,column.Name.Length-2)+"
"+column.Name.Substring(0,column.Name.Length-2)+"\n{\n\t";
Att+="get\n\t{\t\treturn
"+"_"+column.Name.Substring(0,column.Name.IndexOf("Id"))+";\n\t}\n";
Att+="\tset\n\t{\t\t_"+column.Name.Substring(0,column.Name.Length-2)+"=value;\n\t}\n";
Att+="}\n\n"; } else { string
type=GetType(column); Mem+=type+"
_"+column.Name+";\n\n"; Att+=type+"
"+column.Name+"\n{\n\t"; Att+="get\n\t{\t\treturn
"+"_"+column.Name+";\n\t}\n";
Att+="\tset\n\t{\t\t_"+column.Name+"=value;\n\t}\n";
Att+="}\n\n"; } return Mem+Att;
} public string GetType(ColumnSchema
column) { switch (column.DataType){
case DbType.AnsiString: return "string";
case DbType.AnsiStringFixedLength: return
"string"; case DbType.Binary: return
"byte[]"; case DbType.Boolean: return
"bool"; case DbType.Byte: return
"int"; case DbType.Currency: return
"decimal"; case DbType.Date: return
"DateTime"; case DbType.DateTime: return
"DateTime"; case DbType.Decimal: return
"decimal"; case DbType.Double: return
"double"; case DbType.Guid: return
"Guid"; case DbType.Int16: return
"short"; case DbType.Int32: return
"int"; case DbType.Int64: return
"long"; case DbType.Object: return
"object"; case DbType.SByte: return
"sbyte"; case DbType.Single: return
"float"; case DbType.String: return
"string"; case DbType.StringFixedLength:
return "string"; case DbType.Time: return
"DateTime"; case DbType.UInt16: return
"ushort"; case DbType.UInt32: return
"uint"; case DbType.UInt64: return
"ulong"; case DbType.VarNumeric: return
"decimal"; } return
""; } </script>
// Description: Enter summary here after
generation. // --------------------- // Copyright .
<%= DateTime.Now.Year %> Our Client //
--------------------- // History // <%=
DateTime.Now.ToString() %>
using System; using System.Collections;
namespace <%=NameSpace
%> { #region region Entity public
class <%= SourceTable.Name %> {
public <%= SourceTable.Name %>() {
} <% for (int i = 0; i <
SourceTable.Columns.Count; i++) { %> <%=
GetMemberAndAtt(SourceTable.Columns[i]) %> <%
} %> } #endregion
#region EntityCollection public class <%=
SourceTable.Name %>Collection:CollectionBase {
public <%= SourceTable.Name %> this[int
index] { get {return (<%=
SourceTable.Name %>)List[index];} set {List[index] =
value;} }
public int Add(<%= SourceTable.Name %>
value) { return (List.Add(value));
}
public int IndexOf(<%= SourceTable.Name
%> value) { return
(List.IndexOf(value)); }
public void Insert(int index, <%=
SourceTable.Name %> value) {
List.Insert(index, value); }
public void Remove(<%= SourceTable.Name
%> value) {
List.Remove(value); }
public bool Contains(<%= SourceTable.Name
%> value) { return
(List.Contains(value)); } }
#endregion } |