<#@ 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,"Context");
	new DirectoryInfo(outputPath).Create();

    var manager = new Manager(Host, GenerationEnvironment, true) { OutputPath = outputPath };
    var entities = EntityHelper.GetEntities(connectionString, database);
	
    manager.StartBlock("PerformanceDbContext.cs");
#>

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using System;

namespace Performance.EntityModels
{
    public partial class PerformanceDbContext : DbContext
    {
        public PerformanceDbContext(DbContextOptions<PerformanceDbContext> options)
            : base(options)
        {
        }

<#
    foreach(Entity entity in entities)
    {
#>
		/// <summary> <#= entity.EntityComment #> </summary>
        public virtual DbSet<<#= entity.EntityName #>> <#= entity.EntityName #> { get; set; }
<#      
    }
#>
    }
}
<#
    manager.EndBlock(); 
    manager.Process(true);
#>
