Notes on the use of dapper 2

Source: Internet
Author: User

public class T_sodtl
{
[System.ComponentModel.Description ("Keyseq")]
Public Guid ID {get; set;}//The column name in the database keyseq

[System.ComponentModel.Description ("Sokeyseq")]
Public Guid sokeyseq {get; set;}

[System.ComponentModel.Description ("ItemId")]
public string ItemNo {get; set;}

[System.ComponentModel.Description ("ItemName")]
public string ItemName {get; set;}

[System.ComponentModel.Description ("Price")]
Public decimal price {get; set;}

[System.ComponentModel.Description ("Qty")]
Public decimal quality {get; set;} column names in the database qty

[System.ComponentModel.Description ("Amount")]
Public decimal Amount {get; set;}
}

Sqlmapper.itypemap---> Custompropertytypemap

Create a custom map
var map = new Custompropertytypemap (typeof (T_SODTL),
(type, columnName) = = type. GetProperties ()
. Where (prop = Prop. GetCustomAttributes (False). Oftype<descriptionattribute> (). Any (attr = attr. Description = = columnName)//Find the properties of decsription = Column
. FirstOrDefault ());

Dapper.SqlMapper.SetTypeMap (typeof (T_SODTL), map);

Inquire
DbConnection con = this. Getconnection ();
Return con. Query<t_sodtl> ("select * from DBO.T_SODTL where sokeyseq = @SoKeySeq", new {sokeyseq = Sokeyseq}). ToList ();

Insert (note the name of the parameter corresponds to the Entity property)
String strSQL = @ "
INSERT into Dbo.t_so (Keyseq,sono,sodate,customername,remark)
VALUES (@KeySeq, @SoNo, @SoDate, @CustomerName, @Remark) ";
DbConnection con = this. Getconnection ();
Con. Execute (strSQL, new {keyseq = so. Keyseq, SoNo = so. SoNo, sodate = so. Sodate, CustomerName = so. CustomerName, Remark = so. Remark});
Con. Execute (strSQL, so);

Notes on the use of dapper 2

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.