一、T4模板说明

1.T4模板是用来生成Model层实体类的

2.文件后缀为.tt

3.需要修改配置主要有:引用的SqlSugar.dll的位置、生成实体类的位置及生成实体类的命名空间

4.T4模板生成代码对数据库有要求,数据库应该是不区分大小写的,如果你创建的数据库是否区分大小写的“Chinese_PRC_CS_AS ”,

5.T4模板生成代码,中包括创建的视图

那么会抛出异常 'SYSOJBECTS'对象无效,关于修改数据库是否区分大小写可以参考:http://blog.csdn.net/u011127019/article/details/53283251

二、T4模板使用步骤

1.创建项目后,引用SqlSugar.dll

2.添加T4模板:右键项目,选择【运行时文本模板】,后缀为.tt

SqlSugar框架T4模板的使用

还可以,将原Demo中的模板,直接Copy到本项目中

原Demo中的文件内容为:

<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="System.Xml" #>
<#@ assembly name="System.Xml.Linq" #>
<#@ assembly name="System.Data" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="SqlSugar" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Web" #>
<#@ assembly name="$(SolutionDir)\WebTest\App_Lib\SqlSugar.dll" #>

<# 
     

    //当前项目目录
    string projectDir = Host.ResolveAssemblyReference("$(ProjectDir)");

    //解决方案目录
    string solutionDir = Host.ResolveAssemblyReference("$(SolutionDir)");

 
     using (var db = new SqlSugarClient("server=.;Initial Catalog=SqlSugarTest;Persist Security Info=True;User ID=sa;Password=sasa"))
     {
          db.ClassGenerating.CreateClassFiles(db, "E://T4/Models","Models");  

      };
#>
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-19
  • 2021-07-12
猜你喜欢
  • 2021-08-31
  • 2021-07-13
  • 2022-01-15
  • 2021-10-25
  • 2021-10-06
  • 2021-07-29
相关资源
相似解决方案