Pie*_*ter 6 stored-procedures entity-framework
我试图在实体框架中使用一个不返回任何内容的存储过程.存储过程纯粹用于记录.
我添加了一个函数(右键单击 - >添加 - >函数导入),仅当返回值设置为其中一个实体时才起作用.当我将返回类型更改为Int32,Bool或任何其他值或实体之外的任何其他值时,只要我点击构建按钮,函数(方法)就会消失.
关于我如何排序的任何建议?
现在你不能 - 你必须使用模型中定义的一个实体(尽管我认为像INT这样的基本标量类型也应该有用).
使用EF4可以获得更好的效果 - 将于2009年底或2010年初推出.
有关这些新功能的一些信息,请参阅这些文章:
如果你的存储过程纯粹是为了记录,我可能只是在实体框架上下文之外表示它,只是调用存储过程的老式ADO.NET方式....为什么甚至打扰把所有这些都放到EF上下文中?您不是使用此日志记录服务检索,操作和存储数据 - 只需将其作为静态类的静态方法 - 保持简单!
渣
这是从enitity框架执行存储过程的一种方法:
using (SEntities se = new SEntities())
{
EntityConnection entityConnection = (EntityConnection)se.Connection;
DbConnection storeConnection = entityConnection.StoreConnection;
storeConnection.Open();
DbCommand command = storeConnection.CreateCommand();
command.CommandText = "NameOfStoredProcedure";
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("param1", value_of_param1));
command.Parameters.Add(new SqlParameter("param2", value_of_param2));
SqlParameter param3 = new SqlParameter();
pA.SqlDbType = SqlDbType.Bit;
pA.ParameterName = "@param3";
pA.Direction = ParameterDirection.Output;
command.Parameters.Add(param3);
command.ExecuteNonQuery();
returnValue = Convert.ToBoolean(param3.Value);
}
Run Code Online (Sandbox Code Playgroud)