What do you know about Dapper extensions ?, Dapper extension?

Source: Internet
Author: User

What do you know about Dapper extensions ?, Dapper extension?

In my previous ORM comparison article, after I chose Dapper as the underlying ADO basic access framework, I conducted further in-depth research on it, I found that some useful extension methods and features are also extended, so I will briefly talk about the feature labels.

I. TableAttribute features

This is simple, that is, to define the table name for the model. If you do not mark the table name feature, the model type name is removed by default, and this feature can only be marked on the class, it cannot be marked on attributes, methods, and other roles;

Ii. KeyAttribute [implicit] Primary Key Features

Why do I define it as implicit? The key is that if you mark an attribute with it during Insert, the value of this attribute cannot be inserted into the data table, suitable for auto-incrementing primary keys and database primary key fields with assigned values by default

Code Simulation:

[Table ("Person")] public class Person {[Key] public Guid ID {get; set;} public string Name {get; set ;}
Public byte Age {get; set ;}}
// The final script is: insert into [Person] (Name, Age) VALUES (@ Name, @ Age)

Iii. ExplicitKeyAttribute [explicit] Primary Key Features

I was wondering how to define two KEY features before. After trying the DEMO, I found that this can be used to Insert primary KEY values.

Code Simulation:

[Table ("Person")] public class Person {[ExplicitKey] public Guid ID {get; set;} public string Name {get; set;} public byte Age {get; set ;}} // The final script is: insert into [Person] (ID, Name, Age) VALUES (@ ID, @ Name, @ Age)

4. WriteAttribute write-Ability

This is the simplest way to understand. If the attribute is marked as Write (false), it indicates that the data cannot be written, including Insert and Update, so I will not post the code.

V. computedattri features computed

In terms of word understanding, I think this attribute value is calculated by myself and does not participate in any Insert or Update operations, but can read data from the data table, therefore, if you mark this attribute, you cannot write or update the value.

The above expansion features are available in the project: Dapper. when using Contrib, you should pay attention to the reference. This project is also written by Dapper developers. Please use the extension method: Get <T>, GetAll <T>, insert <T>, Update <T>, Delete <T>, DeleteAll <T>

If there is something wrong with the above, please point it out more!

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.