博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
EntityFramework6 Execute Storeprocedure
阅读量:2236 次
发布时间:2019-05-09

本文共 1980 字,大约阅读时间需要 6 分钟。

整个逻辑十分简单,不再赘述,仅作为记录!

1.Function

[Route("api/Module/{id}/{name}")]        public object GetApplicationName(int id,string name)        {            System.Data.SqlClient.SqlParameter[] parameters =            {                new System.Data.SqlClient.SqlParameter("@Id",SqlDbType.Int),                new System.Data.SqlClient.SqlParameter("@Name",SqlDbType.VarChar,50),                new System.Data.SqlClient.SqlParameter("@Result",SqlDbType.VarChar,50),            };            parameters[0].SqlValue = id;            parameters[1].SqlValue = name;            parameters[2].SqlValue = "";            parameters[2].Direction = ParameterDirection.Output;            if(entityContext.Database.Connection.State == ConnectionState.Closed)                entityContext.Database.Connection.Open();            System.Data.Common.DbCommand cmd = entityContext.Database.Connection.CreateCommand();            cmd.CommandText = "prc_demo";            cmd.CommandType = CommandType.StoredProcedure;            cmd.Parameters.AddRange(parameters);            int result = cmd.ExecuteNonQuery();            string output = parameters[2].Value.ToString();            cmd.Connection.Close();            return "result:" + result + ",output:" + output;        }
2.存储过程

USE [EPDB]GO/****** Object:  StoredProcedure [dbo].[prc_demo]    Script Date: 2015/10/26 16:14:17 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO-- =============================================-- Author:		justin-- Create date: 2015-10-26-- Description:	EF work with procedure demo-- =============================================ALTER PROCEDURE [dbo].[prc_demo] 	-- Add the parameters for the stored procedure here	@Id int,	@Name varchar(50),	@Result varchar(50) outputASBEGIN	begin try		begin transaction 			update Applications set Applications.Name = @Name where Applications.Id = @Id;			set @Result = 'SUCCESS';		commit transaction 	end try	begin catch		rollback transaction		set @Result = 'FAIL';	end catchENDGO
3.效果

你可能感兴趣的文章
PHPUnit安装及使用
查看>>
PHP项目用xhprof性能分析(安装及应用实例)
查看>>
composer安装YII
查看>>
Sublime text3快捷键演示
查看>>
sublime text3 快捷键修改
查看>>
关于PHP几点建议
查看>>
硬盘的接口、协议
查看>>
VLAN与子网划分区别
查看>>
Cisco Packet Tracer教程
查看>>
02. 交换机的基本配置和管理
查看>>
03. 交换机的Telnet远程登陆配置
查看>>
微信小程序-调用-腾讯视频-解决方案
查看>>
phpStudy安装yaf扩展
查看>>
密码 加密 加盐 常用操作记录
查看>>
TP 分页后,调用指定页。
查看>>
Oracle数据库中的(+)连接
查看>>
java-oracle中几十个实用的PL/SQL
查看>>
PLSQL常用方法汇总
查看>>
几个基本的 Sql Plus 命令 和 例子
查看>>
PLSQL单行函数和组函数详解
查看>>