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