Csharp: mappings using Dapper-Extensions + Dapper.net .,

Source: Internet
Author: User

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

 

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.