T4 template automatically generates annotated entity class files-requires only one SqlSugar.dll

Source: Internet
Author: User

Creating an entity is as simple as building a DLL in a T4 file and folder.

Using the T4 template Tutorial Step 1

Create T4 template, must be self-new, the T4 code to copy into, many people because of my ready-made T4 error (unexplained)

Click Add File, select "Run-time text template" (suffix. tt) to take a name to determine.

Step 2

Sets the order set required for the current T4 and references SqlSugar.dll

Writing Connection Database code

Call Sqlsugar to generate the entity function and fill in the parameters.

Picture can not see clearly the following code

<#@ TemplateDebug= "false"Hostspecific= "true"Language= "C #"#><#@ ImportNamespace= "System.Collections.Generic"#><#@ AssemblyName= "System.core"#><#@ AssemblyName= "System.Xml"#><#@ AssemblyName= "System.Xml.Linq"#><#@ AssemblyName= "System.Data"#><#@ ImportNamespace= "System.Linq"#><#@ ImportNamespace= "System.Text"#><#@ ImportNamespace= "System.Collections.Generic"#><#@ ImportNamespace= "Sqlsugar"#><#@ ImportNamespace= "System.IO"#><#@ ImportNamespace= "System.Web"#><#@ AssemblyName= "$ (solutiondir) \webtest\app_lib\sqlsugar.dll"#><#//Current project directory stringProjectDir = Host.resolveassemblyreference ("$ (ProjectDir)"); //Solution directory string SolutionDir = Host.resolveassemblyreference ("$ (SolutionDir)"); using (var db = new sqlsugarclient ("Server=.;i Nitial Catalog=sqlsugartest; Persist Security Info=true; User ID=sa; Password=sasa ")) {db. Classgenerating.createclassfiles (db, "E://t4/models", "Models"); };#>               

Step 3

Ctrl+s this T4 template, the entity file is generated, which is included in the project.

If you want to customize some of the formatting of the generated entities, change the templates for these 3 static variables
     var tempitem=classtemplate.itemtemplate;  Class template     var temp=classtemplate.template;  Field Templates

Classtemplate.classfieldsummarytemplate Field Summary Template

The demo is on Git.

Sqlsugar ORM from last year to now has been a year, version from 1.0 to 2.4 Now, this is a stable version, several companies have been projects on-line, Github ranked 7th in the C # most Star Search ORM.

Performance is currently tested down only Chloe ORM can be a higher, but also the following Chloe. The ORM second core-enabled ORM features a slightly higher performance than dapper. (Of course, if you have the test results, I can also send to the posts)

MySql. NET 4.0+

Https://github.com/sunkaixuan/MySqlSugar

MySql. NET CORE

Next week update

MSQL. NET 4.0+:

Https://github.com/sunkaixuan/SqlSugar

MSSQL. NET Core Version

Https://github.com/sunkaixuan/ASP_NET_CORE_ORM_SqlSugar

T4 template automatically generates annotated entity class files-requires only one SqlSugar.dll

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.