动软代码生成与 EntityFramework 实体生成模板

有用到EntityFrameWork的同学们,可以用用。

实体工程中添加EF6的dll

还有

ValidBox4Mvc.ValidRules.dll应用到项目中,此dll下载地址:http://www.cnblogs.com/kewei/p/3548517.html 
<#@ 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 EF=System.ComponentModel.DataAnnotations.Schema;
using EFKey=System.ComponentModel.DataAnnotations;
using ValidBox4Mvc.ValidRules;
namespace TC.Cloud.Public.Model
{
<# if( host.TableDescription.Length > 0) {#> /// <summary>
///<#= host.TableDescription #>
/// </summary>
[Serializable]
[EF.Table("<#= host.GetModelClass(host.TableName) #>")]
<# } #>
public class <#=System.Text.RegularExpressions.Regex.Replace(host.GetModelClass(host.TableName), @"^.*?_", "") #>
{ <# foreach (ColumnInfo c in host.Fieldlist)
{ #>/// <summary>
/// <#= string.IsNullOrEmpty(c.Description) ? c.ColumnName : c.Description #>
/// </summary>
<# if (c.IsPrimaryKey) {#>[EFKey.Key]<#}#>
<# if (c.TypeName =="varchar") {#>[Length(<#=Convert.ToInt32(c.Length)/2 #>)]<#} if (c.TypeName =="nvarchar") {#> [Length(<#=c.Length #>)]<#}#>
<# if (!c.Nullable) {#>[Required(ErrorMessage = "<#= string.IsNullOrEmpty(c.Description) ? c.ColumnName : c.Description #>不能为空")]<#}#>
[EF.Column("<#= c.ColumnName #>")]
public <#= CodeCommon.DbTypeToCS(c.TypeName) #> <#=System.Text.RegularExpressions.Regex.Replace(c.ColumnName, @"^.*?_", "") #>{ get;set; }
<# } #> }
}

不带验证的

<#@ 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 <#= host.NameSpace #>.Model<# if( host.Folder.Length > ) {#>.<#= host.Folder #><# } #>
{
<# if( host.TableDescription.Length > ) {#>
//<#= host.TableDescription #>
<# } #>
public class <#= host.GetModelClass(host.TableName) #>
{ <# foreach (ColumnInfo c in host.Fieldlist)
{ #>/// <summary>
/// <#= string.IsNullOrEmpty(c.Description) ? c.ColumnName : c.Description #>
/// </summary>
[Display(Name = "<#= string.IsNullOrEmpty(c.Description) ? c.ColumnName : c.Description #>")]
public <#= CodeCommon.DbTypeToCS(c.TypeName) #> <#= c.ColumnName #>
{
get;
set;
}
<# } #> public <#= host.GetModelClass(host.TableName) #>(<# int i=; foreach (ColumnInfo c in host.Fieldlist) { #><#=CodeCommon.DbTypeToCS(c.TypeName) #> _<#= c.ColumnName #><# if(i!=host.Fieldlist.Count) { #>,<# }#> <# i++; } #>)
{ <#foreach(ColumnInfo c in host.Fieldlist) { #>
this.<#= c.ColumnName#>= _<#= c.ColumnName#>;<# } #>
} public <#= host.GetModelClass(host.TableName) #>(){} }
}

vs2013批量删除空行 :^\s\S*$\n

动软代码生成与 EntityFramework  实体生成模板

上一篇:Java中的字符串分割 .


下一篇:Java中split的用法