存储过程中MVC5没有返回值 [英] Store Procedure not return value in MVC5
问题描述
我在MVC5通过分贝的工作方式与实体框架。我使用MySQL作为数据库。我创建了一个程序,并在拨打步骤在MySQL它的工作为我的意料。但是,当我在MVC中使用的过程还给每一次0。
I am working in MVC5 with Entity Framework through db approach. I use Mysql as database. I create a procedure and when Call Procedure in Mysql it work as my expectation. But when i use procedure in MVC it return every time 0.
存储过程
CREATE PROCEDURE `checkSeasonAvailability`(
IN paramSeasonId INT,
IN paramHotelId INT,
IN paramStartDate varchar(20),
IN paramEndDate varchar(20)
)
BEGIN
DECLARE _startDate,_endDate DATETIME;
DECLARE _hotelseasonID BIGINT(20);
DECLARE _count,_rowCount,_dateDiff INT;
DECLARE _index INT DEFAULT 1;
DECLARE i INT DEFAULT 0;
DECLARE cursorSeasonList CURSOR FOR SELECT `hotel_season_id`,`start_date`,`end_date`
FROM hotel_season_link
WHERE hotel_id = paramHotelId &&
season_id = paramSeasonId &&
active = TRUE;
OPEN cursorSeasonList;
SET _rowCount=FOUND_ROWS();
SET _count=_rowCount;
IF(_rowCount>0) THEN
Proc:WHILE _index <= _rowCount DO
FETCH cursorSeasonList INTO _hotelseasonID,_startDate,_endDate;
SET _dateDiff=datediff(paramEndDate,paramStartDate);
SET i=0;
WHILE i <= _dateDiff DO
SELECT COUNT(*) FROM hotel_season_link
WHERE
adddate(paramStartDate,i) BETWEEN _startDate AND _endDate INTO _count;
IF(_count>0) THEN
SELECT 1;
LEAVE Proc;
END IF;
SET i=i+1;
END WHILE;
SET _index=_index+1;
END WHILE;
END IF;
END
CALL checkSeasonAvailability(1,3,'2014-12-26 00:00:00','2014-12-31 00:00:00');//call in mysql
控制器
String format = "yyyy-MM-dd hh:mm:ss";
var status = db.checkSeasonAvailability(seasonId, hotelId, startDate.ToString(format), endDate.ToString(format));
在调试我的$ C C I找到所有需要的参数发送成功,但我没有得到返回值。
如果有任何事情错在我的code,所以请给我建议。
When i debug my code i find all required parameter send successfully but i didn't get return value. If any thing wrong in my code so please suggest me.
推荐答案
我自己解决这个问题。我做在存储过程和行为方式的变化。
i solve this problem by myself. I make changed in store procedure and action method.
我在为输出并存储在返回这个变量值的过程添加一个参数。
I add one more parameter in my procedure as OUTPUT and store return value in this variable.
OUT Flag int
SET Flag=0;
SELECT Flag;
然后使操作方法的变化。
Then make change in action method.
String format = "yyyy-MM-dd hh:mm:ss";
System.Data.Entity.Core.Objects.ObjectParameter flag = new System.Data.Entity.Core.Objects.ObjectParameter("flag", typeof(int));
var status = db.checkSeasonAvailability(hotelSeasonId,seasonId, hotelId, startDate.ToString(format), endDate.ToString(format), flag);
这篇关于存储过程中MVC5没有返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!