利用动软代码生成器 自动生成LINQ需要用的数据实体类 (转)

首先先建立一个模板 名称随意 我起的“生成数据实体.cmt”

 

代码如下:

<#@ template language="c#" HostSpecific="True" #>
<#@ output extension= ".cs" #>
<#
	TableHost host = (TableHost)(Host);
	host.Fieldlist.Sort(CodeCommon.CompareByintOrder);
#>
using System; 
using System.Text;
using System.Collections.Generic; 
using System.Data;
namespace <#= ClassName #>  
{
<# if( host.TableDescription.Length > 0) {#>
 //<#= host.TableDescription #>
<# } #>
		[Table(Name = "<#= host.TableDescription #>")]
		public class <#= host.TableName #>Model
		{
		   
		[Column(Name = "<#= CodeCommon.GetFieldstrlist(host.Keys,true) #>",IsPrimaryKey = true,IsDbGenerated = true, AutoSync = AutoSync.OnInsert)]
	<# 
	   int i=0;
	  foreach (ColumnInfo c in host.Fieldlist)
	    { #>
	    <# if(i!=0){ #>
	  [Column(Name = "<#= c.ColumnName #>")]
	    <# }#>
	  	public <#= CodeCommon.DbTypeToCS(c.TypeName) #> <#= c.ColumnName #> { get; set; }
		<#  i++; } #>
  }
}

<#+
string ClassName ="类名随意起";
#>

 

posted on 2015-07-09 01:11  血吸虫  阅读(461)  评论(0编辑  收藏  举报

导航