Unable to Execute Stored Procedure from EF Core

Kmcnet 1,006 Reputation points
2023-02-13T22:08:53.9733333+00:00

Hello and thanks for the help in advance. I am trying to execute a sproc that copies one record from a staging table to a permanent table using the ID from the staging table as the parameter. I have verified the sproc works correctly using the SQL Server management console. But when I execute from EF, the sproc does not appear to execute and the record does not copy from one table to another. I have had similar issues executing sprocs from EF, but can't seem to get the hang of this. Here is my code:



                using (var ctxtest = new myDbContext())
                {
                    //  Copying 
                    var resp = ctxtest.tbl_Log_Registry_Staging.FromSqlRaw("Exec sp_CopyRegistryStagingToRegistry @ID", new SqlParameter("@ID", 58));                   

                }

The code does not seem to generate any error messages.  Any help would be appreciated.
Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
779 questions
{count} votes

1 answer

Sort by: Most helpful
  1. SCRIBE Patrice 41 Reputation points
    2023-02-21T09:50:29.8566667+00:00

    Hi,

    I would start by using a breakpoint to make sure this code is called and check if the expected entity is returned.

    Also as the id is hardcoded, what if you run this twice or if the id doesn't exists ? Sometimes it can be that you run/check agaisnt the wrong database or that your code hide exceptions.

    Finally I helped once someone wo deleted test records after his insert statement.

    In short make first sure that it really fails rather than it actually runs under unexcepted circumstances.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.