Csharp: mappings using Dapper-Extensions + Dapper.net .,
SQL:
CREATE TABLE [PotoUsers] ( [UserID] INT IDENTITY(1,1) PRIMARY KEY, [UserName] NVARCHAR(50), [FirstName] NVARCHAR(50), [LastName] NVARCHAR(50), [MiddleName] NVARCHAR(50), [EmailID] NVARCHAR(50), [Adddate] datetime ) GO
/// <Summary> // 20180212 // tu juwen // </summary> // [Table ("PotoUsers")] public class PotoUsers {// <summary> //// </summary> // [Key] public int UserID {get; set ;} /// <summary> ///// </summary> public string UserName {get; set ;} /// <summary> ///// </summary> public string FirstName {get; set ;} /// <summary> ///// </summary> public string LastName {get; set ;} /// <summary> ///// </summary> public string MiddleName {get; set ;} /// <summary> ///// </summary> public string EmailID {get; set ;} /// <summary> ///// </summary> public DateTime Adddate {get; set ;}}
/// <Summary> /// tu juwen // 20180212 /// </summary> public static class Mappings {public static void Initialize () {DapperExtensions. dapperExtensions. defaultMapper = typeof (PluralizedAutoClassMapper <>); DapperExtensions. dapperExtensions. setMappingAssemblies (new [] {typeof (Mappings ). assembly});} // <summary> //// </summary> public class PotoUsersMapper: classMapper <PotoUsers >{/// <summary> ///// </summary> public PotoUsersMapper () {Table ("PotoUsers "); // DuPotoUsers Map (Ducel => Ducel. userID ). column ("UserID "). key (KeyType. identity); // Map (Ducel => Ducel. userName ). column ("UserName"); Map (Ducel => Ducel. firstName ). column ("FirstName"); Map (Ducel => Ducel. lastName ). column ("LastName"); Map (Ducel => Ducel. middleName ). column ("MiddleName"); Map (Ducel => Ducel. emailID ). column ("EmailID"); Map (Ducel => Ducel. adddate ). column ("Adddate"); AutoMap ();}}}
String connStr = System. configuration. configurationManager. connectionStrings ["conDuString"]. toString (); /// <summary> //// </summary> /// <param name = "sender"> </param> /// <param name = "e "> </param> protected void Page_Load (object sender, eventArgs e) {if (! Page. isPostBack) {try {using (SqlConnection cn = new SqlConnection (connStr) {// 1 get the value // cn. open (); // int UserID = 1; // PotoUsers potoUsers = cn. get <PotoUsers> (UserID); // cn. close (); // Response. write (person. userName); // 2 insert value // cn. open (); // PotoUsers potoUsers = new PotoUsers {UserName = "geovindu", MiddleName = "", EmailID = "geovindu@163.com", FirstName = "Foo ", lastName = "Bar", Adddate = DateTime. now}; // int id = cn. insert (person); // cn. close (); // 3 modify // cn. open (); // int UserID = 1; // PotoUsers potoUsers = cn. get <PotoUsers> (UserID); // potoUsers. userName = "tu juwen"; // potoUsers. lastName = "du"; // potoUsers. firstName = "geovin"; // cn. update (potoUsers); // cn. close (); // 4. delete // cn. open (); // int UserID = 1; // PotoUsers potoUsers = cn. get <PotoUsers> (UserID); // cn. delete (potoUsers); // cn. close (); // 5. cn. open (); var predicate = Predicates. field <PotoUsers> (f => f. userID, Operator. like, true); IEnumerable <PotoUsers> list = cn. getList <PotoUsers> (predicate); cn. close (); Response. write (list. toList <PotoUsers> (). count. toString () ;}} catch (SqlException ex) {Response. write (ex. message. toString ());}}}
Https://github.com/zzzprojects/Dapper-Plus
Https://github.com/tmsmith/Dapper-Extensions
Https://github.com/ericdc1/Dapper.SimpleCRUD