views:

108

answers:

2

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?

A: 

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

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

zeeshanhirani