<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ include file=".\EntityHelper.ttinclude" #>
<#@ include file=".\T4Manager.ttinclude" #>
<#     
    // 数据库连接
    var connectionString = @"server=192.168.18.166;database=db_performance;uid=root;pwd=1234qwer;port=3306;";

    // 需要解析的数据库
    var database = new List<string> { "db_performance" };
	
	DirectoryInfo directory = new DirectoryInfo(Host.TemplateFile);
	var outputPath = Path.Combine(directory.Parent.Parent.FullName,"entity");
	new DirectoryInfo(outputPath).Create();

    var manager = new Manager(Host, GenerationEnvironment, true) { OutputPath = outputPath };
    var entities = EntityHelper.GetEntities(connectionString, database);

    foreach(Entity entity in entities)
    {
        manager.StartBlock(entity.EntityName + ".cs");
#>
//-----------------------------------------------------------------------
// <copyright file=" <#= entity.EntityName #>.cs">
// * FileName: <#= entity.EntityComment #>.cs 
// </copyright>
//-----------------------------------------------------------------------
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Performance.EntityModels	
{
    /// <summary>
    /// <#= entity.EntityComment #>
    /// </summary>
    [Table("<#= entity.EntityName #>")]
	public class <#= entity.EntityName #>
    {
<#
        for(int i = 0; i < entity.Fields.Count; i++)
        {
            if(entity.Fields[i].Key == "PRI"){
#>        /// <summary>
        /// <#= entity.Fields[i].Comment #>
        /// </summary>
        [Key]
		public <#= entity.Fields[i].Type #> <#= entity.Fields[i].Name #> { get; set; }
<#
            }
            else{
#>    
        /// <summary>
        /// <#= entity.Fields[i].Comment #>
        /// </summary>
        public <#= entity.Fields[i].Type #> <#= entity.Fields[i].Name #> { get; set; }
<#            }
        }
#>
    }
}
<#        
        manager.EndBlock(); 
    }

    manager.Process(true);
#>
