1. 接口为ExecuteStoredProcedure(string storedProcedureName, params ObjectParameter[] parameters)
2. 参数为存储过程名字, 及输入值。
3. 思路:创建连接(连接中指定了是Sql/MySql/ODBC等等); 创建通用DbCommand;更改Text以及Type;添加通用Parameter(DBParameter是抽象类,因此需要判断connection类型);判断连接状态(需Open); 调用Execute方法; 关闭连接。
4.
实现如下:

// In V1 of the EF, the context connection is always an EntityConnection
EntityConnection entityConnection = (EntityConnection)protocolDB.Connection; // The EntityConnection exposes the underlying store connection
DbConnection storeConnection = entityConnection.StoreConnection;
DbCommand command = storeConnection.CreateCommand();
command.CommandText = storedProcedureName;
command.CommandType = CommandType.StoredProcedure; if (storeConnection is SqlConnection)
{
foreach (ObjectParameter p in parameters)
{
command.Parameters.Add(new SqlParameter { ParameterName = p.Name, Value = p.Value });
}
}
else if (storeConnection is MySqlConnection)
{
foreach (ObjectParameter p in parameters)
{
command.Parameters.Add(new MySqlParameter { ParameterName = p.Name, Value = p.Value });
}
}
else
{
return enProtocolDBReturnCodes.OPERATION_FAILED;
} bool openingConnection = command.Connection.State == ConnectionState.Closed;
if (openingConnection)
{
command.Connection.Open();
} command.ExecuteNonQuery(); if (openingConnection && command.Connection.State == ConnectionState.Open)
{
command.Connection.Close();
}

最新文章

  1. mongodb 3.x 之实用新功能窥看[2] ——使用$lookup做多表关联处理
  2. angular使用post、get向后台传参的问题
  3. 多边形碰撞 -- SAT方法
  4. Sqlserver 函数(例子)
  5. 关于Yii2中CSS,JS文件的引入心得
  6. org.hibernate.QueryException: could not resolve property
  7. 数据结构【二】:简单阻塞队列BlockingQueue
  8. Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 1) A. Bear and Poker 分解
  9. 【转】C#路径/文件/目录/I/O常见操作汇总
  10. 基于Predictive Parsing的ABNF语法分析器(十)——AbnfParser文法解析器之数值类型(num-val)
  11. C++实现引用和被引用对象分离
  12. App.config自定义节点读取
  13. 如何在电脑上配置两个tomcat
  14. F#周报2019年第9期
  15. java数据结构分析
  16. Django积木块六——验证用户是否登录
  17. 获取DataSet中某行某列的数据
  18. TensorFlow实战Google深度学习框架10-12章学习笔记
  19. 用智能TFT液晶模块这种串口屏做产品界面设计太简单了,大大的节省了开发时间
  20. MySQL的nnodb引擎表数据分区存储

热门文章

  1. JDK设置Encoding编码格式
  2. 认识XmlReader
  3. C#中图片.BYTE[]和base64string的转换
  4. C#抓取网面上的html内容(JS动态生成的无法抓取)
  5. Matlab时频图
  6. 九度OJ 1049:字符串去特定字符 (基础题)
  7. mac sublime text 3 add ctags plugin
  8. HNOI2016
  9. 20145239杜文超 实验五 Java网络编程
  10. Spring Boot2.0之 jar打包方式