T4 template automatically generates object class files with annotations, t4 object

Source: Internet
Author: User

T4 template automatically generates object class files with annotations, t4 object

It is so easy to generate an object. You only need to create a T4 file and put a DLL in the folder.

 

Step 1

Create a T4 template. If you do not have one, you can use it in my DEMO.

 

 

Step 2

Sets the sequence set required by the current T4 and references SqlSugar. dll

Write database connection code

Call SqlSugar to generate the object function and fill in the parameters.

 

 

The image cannot be clearly viewed. See the following code.

<# @ 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 "#> <# // The current project directory string projectDir = Host. resolveAssemblyReference ("$ (ProjectDir)"); // solution directory 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") ;}#>T4 code

 

 

Step 3

CTRL + S: This T4 template generates an object file, which can be included in the project.

 

 

All the demos are on GIT.

SqlSugar ORM has been around for a year since last year, and the version has been upgraded from 1.0 to 2.4. This is a stable version, and several companies have launched projects, github ranks 7th by C # most star for ORM search.

Currently, only chloe ORM can compete in performance tests. It is also the second ORM supporting CORE following chloe. ORM, and its performance is slightly higher than Dapper. (If you have test results, I can also post them)

 

MySql. NET 4.0 +

Https://github.com/sunkaixuan/MySqlSugar

 

MySql. NET CORE

Updated next week

 

MSQL. NET 4.0 +:

Https://github.com/sunkaixuan/SqlSugar

 

MSSQL. NET Core version

Https://github.com/sunkaixuan/ASP_NET_CORE_ORM_SqlSugar

 

Related Article

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.