Store Procedure not return value in MVC5

穿精又带淫゛_ 提交于 2019-12-18 05:25:11

问题


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.

Store Procedure

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

Controller

String format = "yyyy-MM-dd hh:mm:ss";
var status = db.checkSeasonAvailability(seasonId, hotelId, startDate.ToString(format), endDate.ToString(format));

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.


回答1:


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);


来源:https://stackoverflow.com/questions/27596869/store-procedure-not-return-value-in-mvc5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!