开发者

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 o开发者_如何学Pythonf" to None I don't get the stored procedure as a method on the Data Context. How do I run this stored procedure?

I am using Entity Framework 4 with Self Tracking Entities. 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?


You also use the direct sytax with sql like below. db.ExecuteStoreCommand("exe myproc");


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:

            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();
            }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜