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