我正在使用 EF 6.0 和 Mysql。我的存储过程是
delimiter $$
use ge_wv8g73$$
CREATE PROCEDURE Get_UserMapSelections(IN p_userId int)
BEGIN
SELECT @DefaultMap := ValueLong FROM userselections WHERE section = 'Last
Selections' and userid = p_userId and Description like 'LastSelectedMapID';
SELECT CONCAT(
(SELECT IFNULL(
@DefaultMap ,'0')
) ,',', (
SELECT ValueLong FROM userselections where section = 'Last Selections' and userid = p_userId
and Description like concat('MapPage', @DefaultMap)),',',(
SELECT ValueLong FROM userselections where section = 'Last Selections' and userid = p_userId
and Description like concat('MapRow', @DefaultMap)),',',(
SELECT ValueLong FROM userselections where section = 'Last Selections' and userid = p_userId
and Description like concat('MapCol', @DefaultMap))) as selections;
END$$
当我在 mysql 工作台中调用它时,它返回不同的结果
59,147,8,579
但是当我使用 EF 通过代码调用它时,结果仅为 59
GE_Context.cs
public string Get_UserMapSelections(int userId)
{
StringBuilder spCommand = new StringBuilder();
MySqlParameter[] mySqlParams = new MySqlParameter[] { new MySqlParameter("p_userId", userId)
};
spCommand.Append("CALL Get_UserMapSelections(@p_userId);");
try
{
return this.Database.SqlQuery<string>(spCommand.ToString(), mySqlParams).First();
}
catch { return null; }
}
可能是什么问题?有时,当我使用与表中的字段名称相同的参数名称时,例如,如果我使用了
select * from maps where userid = userid
但这里的情况并非如此。
最佳答案
您的 EF 框架代码:
return this.Database.SqlQuery(spCommand.ToString(), mySqlParams).First();
您仅返回第一行。因此您只得到 1 个结果
关于c# - 从代码调用时Mysql存储过程结果不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47384326/