我已经从MySQL数据库生成了EF4模型,并且包含了StoredProcedures和Tables。如何使用EntityFramework调用存储过程?
我知道如何定期对EF进行instert/update/fetch/delete操作,但是找不到我的StoredProcedures。
这正是我所期待的:
using (Entities context = new Entities())
{
context.MyStoreadProcedure(Parameters);
}
编辑1:
这是如何看起来不EF:
sqlStr = "CALL updateGame(?,?,?,?,?,?,?)";
commandObj = new OdbcCommand(sqlStr, mainConnection);
commandObj.Parameters.Add("@id,", OdbcType.Int).Value = inGame.id;
commandObj.Parameters.Add("@name", OdbcType.VarChar, 255).Value = inGame.name;
commandObj.Parameters.Add("@description", OdbcType.Text).Value = ""; //inGame.description;
commandObj.Parameters.Add("@yearPublished", OdbcType.DateTime).Value = inGame.yearPublished;
commandObj.Parameters.Add("@minPlayers", OdbcType.Int).Value = inGame.minPlayers;
commandObj.Parameters.Add("@maxPlayers", OdbcType.Int).Value = inGame.maxPlayers;
commandObj.Parameters.Add("@playingTime", OdbcType.VarChar, 127).Value = inGame.playingTime;
return Convert.ToInt32(executeScaler(commandObj));
PS。如果需要的话我可以改变EF版本
编辑1:
CREATE DEFINER=`106228`@`%` PROCEDURE `updateGame`(
inId INT,
inName VARCHAR(255),
inDescription TEXT,
inYearPublished DATETIME,
inMinPlayers INT,
inMaxPlayers INT,
inPlayingTime VARCHAR(127)
)
我不明白,为什么我应该对SP名称进行硬编码?我在生成模型时添加了它们?应该不只是在Context对象上的某个地方作为方法? – Ivy