实体框架4存储过程返回无

时间:2010-07-08 08:44:46

标签: c# entity-framework-4

如果我在Entity Framework 4中为存储过程创建函数导入并将“返回集合”设置为“无”,则不会将存储过程作为数据上下文中的方法获取。如何运行此存储过程?

我正在使用具有自我跟踪实体的实体框架4。就我所见,所有其他返回类型似乎对我都有效,生成一个方法,我可以调用它来运行存储过程 - 只是当我选择None作为返回类型时?

2 个答案:

答案 0 :(得分:0)

看起来自我跟踪实体在没有返回任何实例时不会生成运行存储过程的方法。所以我认为你必须像往常一样创建函数import,然后手动运行存储过程,我正在做如下:

            using (TestEntities entities = new TestEntities())
            {
                DbConnection connection = entities.Connection;
                connection.Open();
                DbCommand command = connection.CreateCommand();
                command.CommandType = CommandType.StoredProcedure;
                command.CommandText = "TestEntities.CustomerDelete";
                command.Parameters.Add(new EntityParameter("CustomerId", DbType.Int32) { Value = 1 });
                command.ExecuteScalar();
                connection.Close();
            }

答案 1 :(得分:0)

您还可以使用直接sytax和sql,如下所示。 db.ExecuteStoreCommand(“exe myproc”);

相关问题