简体   繁体   English

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

[英]Entity Framework 4 Stored Procedure Returns None

If I create a function import for a stored procedure in Entity Framework 4 and set "Returns a collection of" to None I don't get the stored procedure as a method on the Data Context. 如果在Entity Framework 4中为存储过程创建函数导入并将“返回的集合归还”设置为“无”,则不会将存储过程作为数据上下文中的方法获得。 How do I run this stored procedure? 如何运行此存储过程?

I am using Entity Framework 4 with Self Tracking Entities. 我正在使用带有自我跟踪实体的Entity Framework 4。 All the other return types seem to work ok for me as far as I can see, a method is generated which I can call to run the stored procedure - just not when I select None as the return type? 据我所知,所有其他返回类型似乎对我都工作正常,生成了一个可以调用以运行存储过程的方法-只是当我选择None作为返回类型时,不是吗?

Looks like Self Tracking Entities won't generate methods to run Stored Procedures when they return none. 自我跟踪实体看起来什么也不返回运行存储过程的方法。 So I believe you have to create the function import as normal and then run the stored procedure manually which I am doing as below: 因此,我相信您必须像往常一样创建函数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();
            }

You also use the direct sytax with sql like below. 您还可以将直接语法与sql一起使用,如下所示。 db.ExecuteStoreCommand("exe myproc"); db.ExecuteStoreCommand(“ exe myproc”);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM