简体   繁体   中英

Entityframework not executing Stored Procedure

I have the following piece of code:

using (var context = new MyContext())
        {
            context.Database.CommandTimeout = 5000;

            context.Database.ExecuteSqlCommand("EXEC [DBO].[SP_IMPORT_MYDATA]");

            context.SaveChanges();
        }

When I make the call, the process looks like it is running but nothing is being updated in the database. If I call the Stored Procedure directly from SQL Server Management Studio then it kicks-off right away and loads my data. Anyone see whats going wrong?

For clarity this is the same SP being called in SQL Server and it works fine:

    USE [MyDB]
GO

DECLARE @return_value int

EXEC    @return_value = [dbo].[SP_IMPORT_MYDATA]

SELECT  'Return Value' = @return_value

GO

Why can't you just import the function and call it directly from the context? It should execute just fine.

Update the model from the database, include the desired stored procedure. Use the model browser to find the SP and do "Add function import"

And THEN, you can just do:

context.SP_IMPORT_MYDATA();

More info: http://msdn.microsoft.com/en-us/library/vstudio/bb896231(v=vs.100).aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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