Dapper a lightweight ORM Library

Source: Internet
Author: User

Related reading

http://stackexchange.github.io/dapper-dot-net/

Https://github.com/StackExchange/dapper-dot-net

Https://msdn.microsoft.com/zh-cn/magazine/mt703432.aspx

Reference

Can be downloaded directly through NuGet, the need for source code can be downloaded through git, the above has given a link

  

Basic operations

A simple definition of the MSSQL data sheet

  

        Private StaticList<student>Read () {using(varConnect =NewSqlConnection (connectionString)) {Connect.                Open (); varquery = Connect. Query<student> ("SELECT TOP [Id],[name],[grade] from [TESTDB]. [dbo]. [Student];"); returnquery.            ToList (); }        }        Private Static voidAdd () {using(varConnect =NewSqlConnection (connectionString)) {Connect.                Open (); varresult = Connect. Execute ("INSERT into [dbo]. [Student] ([Id],[name],[grade]) VALUES (@Id, @Name, @Grade);",New[] {                    New{id=2, name="John Doe", grade=1},                    New{id=3, name="Harry", grade=1},                    New{id=4, name="Zhao Liu", grade=1}                }); Console.WriteLine ("affect number of rows {0}", result); }        }        Private Static voidUpdate () {using(varConnect =NewSqlConnection (connectionString)) {Connect.                Open (); varresult = Connect. Execute ("UPDATE [dbo].  [Student] SET [Grade] = @Grade WHERE [email protected]; ",New{Id =2, Grade =2 }); Console.WriteLine ("affect number of rows {0}", result); }        }        Private Static voidDelete () {using(varConnect =NewSqlConnection (connectionString)) {Connect.                Open (); varresult = Connect. Execute ("DELETE from [dbo]. [Student] WHERE Id [email protected]; ",New{Id =1 }); Console.WriteLine ("affect number of rows {0}", result); }        }

Dapper a lightweight ORM Library

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.