0
votes

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. 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?

2

2 Answers

0
votes

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

0
votes

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