基本信息
源码名称:T4模板生成 实体类 项目源码
源码大小:0.38M
文件格式:.zip
开发语言:C#
更新时间:2016-10-19
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 2 元 
   源码介绍


<#@ template debug="true" hostspecific="true" language="C#"  #>
<#@ output extension=".cs" #>
<#@ assembly name="System.Core"#>
<#@ import namespace="System"#>
<#@ import namespace="System.Collections.Generic"#>

<#@ include file="../Code/DBSchema.ttinclude"#>
<#
    var dbSchema=DBSchemaFactory.GetDBSchema();
	List<string> tableList=dbSchema.GetTablesList();
	foreach(string tableName in tableList)
	{
		Table table=dbSchema.GetTableMetadata(tableName);
#>
using System;
using System.Collections.Generic;
using System.Text;

namespace Project.Model
{
	[Serializable]
	public class <#=tableName#>
	{
		#region Constructor
		public <#=tableName#>() { }

		public <#=tableName#>(<#=table.ColumnTypeNames#>)
		{
<#
		foreach(Column c in table.Columns)
		{
#>
			this.<#=c.LowerColumnName#> = <#=c.LowerColumnName#>;
<#
		}
#>
		}
		#endregion

		#region Attributes
<#
		foreach(Column c in table.Columns)
		{
#>
		private <#=GeneratorHelper.GetQuesMarkByType(c.TypeName)#> <#=c.LowerColumnName#>;

		public <#=GeneratorHelper.GetQuesMarkByType(c.TypeName)#> <#=c.UpColumnName#>
		{
			get { return <#=c.LowerColumnName#>; }
			set { <#=c.LowerColumnName#> = value; }
		}
<#
		}
#>
		#endregion

		#region Validator
		public List<string> ErrorList = new List<string>();
		private bool Validator()
		{	
			bool validatorResult = true;
<#
		foreach(Column c in table.Columns)
		{
			if(!c.AllowDBNull)
			{
				if(c.TypeName==GeneratorHelper.StringType)
				{
#>
			if (string.IsNullOrEmpty(this.<#=c.UpColumnName#>))
			{
				validatorResult = false;
				this.ErrorList.Add("The <#=c.UpColumnName#> should not be empty!");
			}
<#
				}
				if(c.TypeName==GeneratorHelper.DateTimeType)
				{
#>
			if (this.<#=c.UpColumnName#>==null)
			{
				validatorResult = false;
				this.ErrorList.Add("The <#=c.UpColumnName#> should not be empty!");
			}
<#
				}
			}
			if(c.TypeName==GeneratorHelper.StringType)
			{
#>
			if (this.<#=c.UpColumnName#> != null && <#=c.MaxLength#> < this.<#=c.UpColumnName#>.Length)
			{
				validatorResult = false;
				this.ErrorList.Add("The length of <#=c.UpColumnName#> should not be greater then <#=c.MaxLength#>!");
			}
<#
			}
		}
#>
			return validatorResult;
		}	
		#endregion
	}
}
<#
	}
	dbSchema.Dispose();
#>