求codesmith template for NHibernate 1.2.0

xiaohuan 2007-07-07 12:20:46
如题

yuanxhsoft@126.com
...全文
454 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
tianxm 2007-07-19
  • 打赏
  • 举报
回复
case "smalldatetime" : case "timestamp" : case "datetime" :
retType = "DateTime" ;

timestamp类型怎么能用DateTime类型来表示呢?错误
Jinglecat 2007-07-15
  • 打赏
  • 举报
回复
不用 NHB 好多年
xiaohuan 2007-07-15
  • 打赏
  • 举报
回复
chaoren1641 2007-07-07
  • 打赏
  • 举报
回复
引用 http://blog.113e.com/117378.shtml
chaoren1641 2007-07-07
  • 打赏
  • 举报
回复
<%@ 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>

vainnetwork 2007-07-07
  • 打赏
  • 举报
回复
给楼主发了吗。
lishijie910123 2007-07-07
  • 打赏
  • 举报
回复
学习一下,
帮顶
xiaohuan 2007-07-07
  • 打赏
  • 举报
回复
for NHibernate 1.2.0 GA
xiaohuan 2007-07-07
  • 打赏
  • 举报
回复
chaoren1641(学啊学,学到外婆桥!):

没有xml的啊

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧