私はMySQLデータベースからEF4モデルを生成しました。私はStoredProceduresとTablesの両方を含んでいます。EntityFrameworkでストアドプロシージャを呼び出す方法
私はEFに対して通常のinstert/update/fetch/delete操作を行う方法を知っていますが、私のStoredProceduresは見つかりません。編集1
using (Entities context = new Entities())
{
context.MyStoreadProcedure(Parameters);
}
:
これは私が望んでいたものだった
これは、それが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