none
How to set parameter datatype in Entity Framework RRS feed

  • Question

  • Hi All,

    Below is my store procedure. This procedure includes 3 cases : to insert, update delete 

    ALTER PROCEDURE [dbo].[sp_Insert_update_delete]
        -- Add the parameters for the stored procedure here
    	@case INT ,
    	@emp_id INT=NULL,
           @emp_name VARCHAR(50) = null,
           @city varchar(50)= null
    
    AS
    BEGIN
    
    IF @case = 1
        BEGIN
     
        SET NOCOUNT ON;
    
            INSERT INTO [dbo].[tblEmployee](emp_name,city)
            VALUES(@emp_name,@city)
    
        SELECT SCOPE_IDENTITY() AS empid
    	END
    
    IF @case = 2
        BEGIN
     
            UPDATE [dbo].[tblEmployee]
    		SET emp_name=@emp_name,city=@city
    		WHERE emp_id=@emp_id
    
    	END
    IF @case = 3
        BEGIN
     
            DELETE FROM [dbo].[tblEmployee]
    		WHERE emp_id=@emp_id
    
    	END
    
    
    
    END

    When I validate EDMX it show error

    Error 1 Error 2037: A mapping function bindings specifies a function DemoDbModelNameSpace.Store.sp_Insert_update_delete but does not map the following function parameters: case

    How to define/use case parameter in EF.

    Please suggest.

    Tuesday, February 12, 2019 3:37 AM

All replies

  • Becuase you are using an EDMX is part of your problem IMO.

    You have the following choices to circumvent the problem:

    1) Split the sproc into 3 different sprocs for the needed functionality eliminating the 'case' parm and still use the EDMX approach.

    2) Leave the sproc as is but use the EF backdoor  to run the sproc traditionally using the parametrized approach to pass the 'case' parm to the sproc taking  the EDMX out of the picture 

    3) Use EF code first to eliminate the EDMX and run the sproc using the parametrized approach to pass the 'case' parm to the sproc.

    Tuesday, February 12, 2019 2:04 PM