摘要:本文主要向大家介绍了SQLServer数据库之C# Dapper 轻量ORM调试对SQLServer,通过具体的内容向大家展现,希望对大家学习SQLServer数据库有所帮助。
本文主要向大家介绍了SQLServer数据库之C# Dapper 轻量ORM调试对SQLServer,通过具体的内容向大家展现,希望对大家学习SQLServer数据库有所帮助。
Dapper简介
Dapper只有一个代码文件,完全开源,你可以放在项目里的任何位置,来实现数据到对象的ORM操作,体积小速度快。 使用ORM的好处是增、删、改很快,不用自己写sql,因为这都是重复技术含量低的工作,还有就是程序中大量的从数据库中读数据然后创建model,并为model字段赋值。这些ORM都可以轻松给你搞定。ORM给我们开发带来便利时,性能也是一个让我们不得不考虑的问题。一般的ORM性能和直接写原生的sql比都差不少,但是Dapper性能还很错,甚至和DbHelperSQL方式性能高出很多。
假如你喜欢原生的Sql语句,又喜欢ORM的简单,那你一定会喜欢上Dapper这款ROM。
Dapper
Dapper 功能实现
1 Dapper 功能实现
2 ///
5 ///
6 ///
7 public int ExecuteBySql(string strSql)
8 {
9 if (dbTransaction == null)
10 {
11 using (var connection = Connection)
12 {
13 return connection.Execute(strSql);
14 }
15 }
16 else
17 {
18 dbTransaction.Connection.Execute(strSql, null, dbTransaction);
19 return 0;
20
21 }
22 }
23 ///
26 ///
27 ///
28 ///
29 public int ExecuteBySql(string strSql, params DbParameter[] dbParameter)
30 {
31 if (dbTransaction == null)
32 {
33 using (var connection = Connection)
34 {
35 return connection.Execute(strSql, dbParameter);
36 }
37 }
38 else
39 {
40 dbTransaction.Connection.Execute(strSql, dbParameter, dbTransaction);
41 return 0;
42
43 }
44 }
45 ///
48 ///
49 ///
50 public int ExecuteByProc(string procName)
51 {
52 if (dbTransaction == null)
53 {
54 using (var connection = Connection)
55 {
56 return connection.Execute(procName);
57 }
58 }
59 else
60 {
61 dbTransaction.Connection.Execute(procName, null, dbTransaction);
62 return 0;
63
64 }
65 }
66 ///
69 ///
70 ///
71 ///
72 public int ExecuteByProc(string procName, params DbParameter[] dbParameter)
73 {
74 if (dbTransaction == null)
75 {
76 using (var connection = Connection)
77 {
78 return connection.Execute(procName, dbParameter);
79 }
80 }
81 else
82 {
83 dbTransaction.Connection.Execute(procName, dbParameter, dbTransaction);
84 return 0;
85
86 }
87 }
本文由职坐标整理并发布,希望对同学们学习SQL Server有所帮助,更多内容请关注职坐标数据库SQL Server数据库频道!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号