1024programmer Asp.Net NET8 ORM uses AOT SqlSugar and EF Core

NET8 ORM uses AOT SqlSugar and EF Core

NET8 ORM uses AOT SqlSugar and EF Core

Introduction to .NET AOT

.Net8’s native precoded machine code NET AOT, which is almost 100% bootstrapped. Microsoft has made a lot of efforts to get rid of the constraints of C++. That is to say, the code is almost rewritten in C#, including virtual machine, GC, memory model, etc. What C++ needs to do is just the boot program. This article looks at the operating mode of this crucial boot program through the code.

.NET support functions

SqlSugar ORM uses AOT to operate the database

SqlSugar has perfectly supported .net aot. The following DEMO includes table creation, insertion, query, deletion and update

After decompression, you can publish it directly into an AOT file

aot_test-master.rar

image.png

Nuget installation

SqlSugarCore
 

 

Add, delete, check and modify code

StaticConfig.EnableAot = true;//Enable AOT. Just start the program and execute it once.

 //Use SqlSugarClient to create new every time, do not use singleton mode
 var db = new SqlSugarClient(new ConnectionConfig()
 {
 IsAutoCloseConnection = true,
 DbType = DbType.Sqlite,
 ConnectionString = "datasource=demo.db"

 },
 it =>
 {
 // Logging SQL statements and parameters before execution
 //Record SQL statements and parameters before execution
 it.Aop.OnLogExecuting = (sql, para) =>
 {
 Console.WriteLine(UtilMethods.GetNativeSql(sql, para));
 };
 });
 return db;
 Supported functions
 //Inquire
 var list=db.Queryable().ToList();
 var list2=db.Queryable().ToDataTable();
 var list3= db.Queryable().Select(it=>new {
 id=it.Id
 }).ToList();

 //Insertion, deletion and update are all OK as long as they are entities and have been tested so far.
 db.Insertable(new Student()
 {
 Id = 1,
 Name = "aa"
 }).ExecuteCommand();
 db.Deleteable(new Student()
 {
 Id = 1,
 Name = "aa"
 }).ExecuteCommand();
 db.Updateable(new Student()
 {
 Id = 1,
 Name = "aa"
 }).ExecuteCommand();

 //Writing sql is also supported
 db.Ado.GetDataTable(sql);
 db.Ado.ExecuteCommand(sql);
 

 

AOT configuration tutorial

Create a class project with AOT

Create a new rd.xml

 
 <Assembly Name="SqlSugar" Dynamic="  span>Required All">
 
 
 

Change project files

<Project Sdk="  Microsoft.NET.Sdk.Web">

 
 net8.0
 enable
 enable
 true
 true
 AnyCPU;x64
 
 
 <RdXmlFile Include="rd.xml  " />
 

RdXmlFile mainly refers to our new rd.xml (this xml must be able to be published)

How to make your own code support AOT

1. There cannot be a dynamic type and can be replaced with object

2. There cannot be emit and can be replaced by an expression tree

3. Some reflections cannot find the constructor or Type needs to configure xml

4. Reflection does not support loading assemblies based on paths. They can be taken out from the Type of a class

5. A c++ error occurs during publishing. You need to install the c++ desktop where you install and update VS

6. Select x64 for publishing and does not support x86 and arm

SqlSugar ORM detailed tutorial

SqlSugar is a veteran .NET open source multi-database architecture ORM framework (EF Core single database architecture), developed by the Fructose Big Data Technology Team

Maintained and updated, the most easy-to-use .NET ORM framework is available out of the box. The ecosystem is rich, and the open source ecosystem is currently second only to EF Core, but when needed

SqlSugar is more preferred among multi-library compatible projects or products [Open Source Ecosystem] [View]��Tutorial】

aot_test-master.rar

EF Core8

AOT is not supported yet

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/net8-orm-uses-aot-sqlsugar-and-ef-core-2/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索