Csharp:mappings using Dapper-extensions+dapper.net.

Source: Internet
Author: User

Sql:

CREATE TABLE [potousers]          (            [UserID] INT IDENTITY (PRIMARY) KEY,            [UserName] NVARCHAR (),            [ FirstName] NVARCHAR, [            LastName] NVARCHAR (+),            [MiddleName] NVARCHAR (+),            [Emailid] NVARCHAR (50),  [Adddate] datetime          )  GO  

  

<summary>    //20180212///TU///potousers//[table    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>///20180212///</summary> public static class Mappings { public static void Initialize () {DapperExtensions.DapperExtensions.DefaultMapper = typeof (Pluralizedaut            oclassmapper<>); DapperExtensions.DapperExtensions.SetMappingAssemblies (new[] {typeof (Mappings).        Assembly}); }///<summary>////</summary> public class potousersmapper:classmapper< potousers> {//<summary>////</summary> public Po Tousersmapper () {Table ("potousers");//dupotousers Map (Ducel = Duce L.userid). Column ("UserID"). Key (keytype.identity); Primary key type 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 Sqlconn Ection (CONNSTR)) {//1 Gets 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 = "[email protected]", FirstName = "Foo", LastName = "Bar", adddate = DateTime.Now}; int id = CN.                        Insert (person); cn.                        Close (); 3 Modify the//CN.                        Open ();                        int UserID = 1; Potousers Potousers = CN.                        Get<potousers> (UserID);                        Potousers.username = "Tu ju wen";                        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

 

Csharp:mappings using Dapper-extensions+dapper.net.

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.