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