储存程序:
CREATE DEFINER=`newdb`@`%` PROCEDURE `GetMaximumIDsCount`(IN AppID INT,IN isBurnCenter INT,IN BurnCenterID INT)
BEGIN
IF isBurnCenter = 1 THEN
SELECT MAX(CAST(b.hospitalid AS SIGNED))
FROM tblhosipital b
WHERE b.appId = AppID AND b.burncenterid IS NULL;
END IF;
IF isBurnCenter = 0 THEN
SELECT MAX(CAST(h.hospitalid AS SIGNED))
FROM tblhosipital h
WHERE h.appId = AppID AND h.burncenterid <> '' AND h.burncenterid = BurnCenterID;
END IF;
END
从applicationdbcontext调用(代码优先)
public virtual ObjectResult<long?> GetMaximumIDsCount2(Nullable<int> appID, Nullable<int> isBurnCenter, Nullable<int> burnCenterID)
{
var appIDParameter = appID.HasValue ?
new ObjectParameter("AppID", appID) :
new ObjectParameter("AppID", typeof(int));
var isBurnCenterParameter = isBurnCenter.HasValue ?
new ObjectParameter("isBurnCenter", isBurnCenter) :
new ObjectParameter("isBurnCenter", typeof(int));
var burnCenterIDParameter = burnCenterID.HasValue ?
new ObjectParameter("BurnCenterID", burnCenterID) :
new ObjectParameter("BurnCenterID", typeof(int));
return ((IObjectContextAdapter)this).ObjectContext.ExecuteStoreQuery<Nullable<long>>("GetMaximumIDsCount @AppID, @isBurnCenter, @BurnCenterID", appIDParameter, isBurnCenterParameter, burnCenterIDParameter);
}
获取异常:
sql语法有错误;请查看与您的mysql服务器版本对应的手册,以了解在第1行的“getmaximumidscount@appid,@isburnchenter,@burnchenterid”附近使用的正确语法
1条答案
按热度按时间mtb9vblg1#
你需要加上
CALL [procedure_name]()
存储过程名称之前的方法:注意:mysql存储过程使用以下语法执行:
注2:使用
FirstOrDefault()
或者SingleOrDefault()
从中只返回一个结果集ObjectResult<T>
:作为补充说明,您可以尝试用声明参数
MySqlParameter
而不是ObjectParameter
:参考文献:
调用语法(mysql)