Location>code7788 >text

: CRUD Assistant for Dapper

Popularity:879 ℃/2024-12-12 20:17:59

We are in the project development, in the face of some high concurrency, large data volume and other business scenarios, often on the SQL statement performance requirements are high, this time in order to facilitate the flexibility of control, we will generally write native SQL.

Dapper is a very high-performance lightweight ORM framework, Dapper using native SQL statements, for CRUD these simple operations we generally encapsulate their own, otherwise it will become very cumbersome.

Today we recommend a CRUD extension library for Dapper, it will meet our needs and reduce our workload.


01 Project Profile

Is an open source project , it is based on Dapper development , for developers to provide simple CRUD operation helper .

Dapper itself is a lightweight ORM framework , which allows developers to use SQL statements to directly manipulate the database , but at the same time can enjoy the convenience of ORM , such as parameterized queries .

Instead, it further simplifies the process, allowing developers to perform CRUD operations more easily.

core function

CRUD operations : Through a simple API , developers can easily perform insert , read , update and delete operations , including Get , GetList , Insert , Update , Delete and so on . By extending the IDbConnection interface, it can be used directly without additional configuration.

Model Attribute Support : By using attributes (such as [Key], [Table], [Column], etc.), you can easily specify the mapping relationship between the model and database tables. Also provides [Editable(false)], [ReadOnly(true)], [IgnoreSelect], [IgnoreInsert], [IgnoreUpdate] and other attributes for controlling the behavior of the model attributes in CRUD operations.

Asynchronous operation support: Asynchronous operation support is provided for applications that need to process large amounts of data or need to improve response time.

02 Usage

1. Define the model

[Table("Users")]
public class User
{
    [Key]
    public int UserId { get; set; }  
    public string FirstName { get; set; }  
    public string LastName { get; set; }  
    public int Age { get; set; }  

    // extra、Properties not in the database
    [Editable(false)]
    public string FullName { get { return ("{0} {1}", FirstName, LastName); } }  
}

2. Execute CRUD operations

// Assuming that there is already an open database connection connection

// Insertion
var newId = (new User { FirstName = "John", LastName = "Doe", Age = 30 }));

// Read operation
var user = <User>(newId);

// Update var user = <User>(newId); // Read
 = 31; (user);; // Update operation.
(user);

// Delete operation
<User>(newId); // Delete operation.

03 Project Address

/ericdc1/

More open source projects: /bianchenglequ/NetCodeTop

- End -

Recommended Reading

2 zero-based introductory framing tutorials!

Html2OpenXml: HTML into OpenXml .Net library , easy to realize Html to Word.

SharpLab: .Net decompiler tool , easy to view the decompiled code in real time !

Inventory of 4 .Net cross-platform graphics open source libraries!

Flurl: a Star 3.9K chained RESTful style HTTP open source .Net library