基本信息
源码名称:使用T4引擎生成数据库表实体Demo
源码大小:0.10M
文件格式:.rar
开发语言:C#
更新时间:2016-10-20
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

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

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


            TableHost host = new TableHost();
            host.Namespace = namespace ;
            host.Classname = classname ;
            host.FileExtension = ".cs";
            host.TemplateFile = templatefile;                    

            SqlConnection conn = new SqlConnection(constring);
            conn.Open();
            DataTable dt = conn.GetSchema("tables");            
            string sql = "select * from "   host.Classname;
            SqlCommand cmd = new SqlCommand(sql, conn);
            SqlDataAdapter ad = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            ad.FillSchema(ds, SchemaType.Mapped, host.Classname );
            host.Dt = ds.Tables[0];

            Microsoft.VisualStudio.TextTemplating.Engine engine = new Microsoft.VisualStudio.TextTemplating.Engine();
            string input = "";
            string output = "";
            input = System.IO.File.ReadAllText(host.TemplateFile);
            output = engine.ProcessTemplate(input, host);

            string outputname = host.Classname   host.FileExtension;

            System.IO.File.WriteAllText(outputname  , output);

            foreach (CompilerError error in host.Errors) {
                textBox1.Text  = error.ToString();
            }
}