读书人

求codesmith template for NHibernate

发布时间: 2012-01-24 23:11:55 作者: rapoo

求codesmith template for NHibernate 1.2.0
如题

yuanxhsoft@126.com

[解决办法]
<%@ CodeTemplate Language= "C# " TargetLanguage= "C# " LinePragmas= "True " %>

<%@ Property Name= "SourceTable " Type= "SchemaExplorer.TableSchema "
Category= "SourceTable "
Description= "一TABLE " %>
<%@ Property Name= "NameSpace " Type= "String "
Category= "Main "
Description= "出文件使用的命名空 " %>
<%@ Property Name= "ClassName " Type= "String "
Category= "Main "
Description= "名 " %>
<%@ Assembly Name= "SchemaExplorer " %>
<%@ Import Namespace= "SchemaExplorer " %>

//***********************************************************************
// Created: <%= DateTime.Now.ToShortDateString() %>
// File: <%= CodeTemplate.GetFileName() %>
// Description: <%= SourceTable.Name %>
//***********************************************************************



using System;

namespace <%= NameSpace %>
{
/// <summary>
/// <%= SourceTable.Name %> class description here.
/// </summary>
public class <%= ClassName %>
{

<% for (int i=0; i <SourceTable.Columns.Count; i++) %>
<% { %>
<% string colName = SourceTable.Columns[i].Name.ToString(); %>
<% //string colType = SourceTable.Columns[i].SystemType.ToString(); %>
<% ColumnSchema colType = SourceTable.Columns[i]; %>
private <%= GetColumnDataType(colType) %> _ <%= FirstToLower(colName) %> <%= GetDefaultValue(GetColumnDataType(colType)) %> ;
<% } %>


#region Constructor

public <%= SourceTable.Name %> ()
{
//
// TODO: <%= SourceTable.Name %> constructure logic
//
}

public <%= SourceTable.Name %> ( <% for (int i=0; i <SourceTable.Columns.Count; i++) %> <% { %> <% string colName = SourceTable.Columns[i].Name.ToString(); %> <% ColumnSchema colType = SourceTable.Columns[i]; %> <%=GetColumnDataType(colType)%> <%=FirstToLower(colName)%> <% if (i <SourceTable.Columns.Count-1) {%> , <% } %> <% } %> )
{
<% for (int i=0; i <SourceTable.Columns.Count; i++) %>
<% { %>
<% string colName = SourceTable.Columns[i].Name.ToString(); %>
_ <%= FirstToLower(colName) %> = <%= FirstToLower(colName) %> ;
<% } %>
}

#endregion




#region Property
<% for (int i=0; i <SourceTable.Columns.Count; i++) %>
<% { %>


<% string colName = SourceTable.Columns[i].Name.ToString(); %>
<% ColumnSchema colType = SourceTable.Columns[i]; %>

public <%= GetColumnDataType(colType) %> <%= colName %>
{
get
{
return _ <%= FirstToLower(colName) %> ;
}
set
{
_ <%= FirstToLower(colName) %> = value;
}
}

<% } %>
#endregion


}
}



<script runat= "template ">

private string FirstToLower(string Str)
{
string S;
S = Str.Substring(0, 1).ToLower() + Str.Substring(1);
return S;
}


private string GetColumnDataType(SchemaExplorer.ColumnSchema ColumnField)
{
string retType= " ";
switch (ColumnField.NativeType.ToLower())
{
case "int " : case "tinyint " : case "smallint " : case "bigint " :
retType = "int " ;
break;
case "decimal " : case "float " : case "money " : case "numeric " : case "smallmoney " :
retType = "double " ;
break;
case "char " : case "nchar " : case "ntext " : case "text " : case "varchar " : case "nvarchar " :
retType = "string " ;
break;
case "smalldatetime " : case "timestamp " : case "datetime " :
retType = "DateTime " ;
break;
case "bit " :
retType = "bool " ;
break;
case "binary " : case "image " : case "varbinary " :
retType = "byte[] " ;
break;
}
return retType;
}



private string GetDefaultValue(string ColumnValue)
{
string retValue= " ";
switch (ColumnValue.ToLower())
{
case "int " : case "double " :
retValue = "= 0 " ;
break;
case "string " :
retValue = "= \ "\ " " ;
break;
case "DateTime " :
retValue = "= System.DateTime.Now " ;
break;
case "bool " :
retValue = "= false " ;
break;
default :
retValue = "= new " + ColumnValue + "() " ;
break;
}
return retValue;
}



</script>


[解决办法]
给楼主发了吗。
------解决方案--------------------


学习一下,
帮顶
[解决办法]
不用 NHB 好多年
[解决办法]
case "smalldatetime " : case "timestamp " : case "datetime " :
retType = "DateTime " ;

timestamp类型怎么能用DateTime类型来表示呢?错误

读书人网 >asp.net

热点推荐