locked
How to avoid to passing all parameter value in stored procedure using .Net Entity model RRS feed

  • Question

  • Hi,

    My stored procedure has 50 parameters(SP name: SPCreateContact) and imported functions name like "fnCreateContact" in entity model.

    But i want to pass only 3 parameters in some situation.

    How i to do?

    I go error message like "No overload method for 3 argument..."

     

    Please help me.

     

    Thanks in advance.

     


    • Edited by P M Karthika Friday, December 16, 2011 3:46 PM
    • Moved by Forrest Guo Tuesday, December 20, 2011 1:32 AM move to appropriate forum (From:.NET Framework Setup)
    Friday, December 16, 2011 8:30 AM

Answers

  • Hi Karthika,

    You should provide Override method for the Import function to provide the default values for other parameters by yourself.

    public int fnCreateContact(int param1,int param2,int param3)
    {
    return  fnCreateContact(int param1,int param2,int param3,........);
    
    }
    

    Like this.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Alan_chen Thursday, December 29, 2011 6:12 AM
    Tuesday, December 20, 2011 8:42 AM
  • Hi PM,

    The method will created based on your Stored Procedure, there is no way to customize this method, the only way is overload the method, thanks for understanding.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Alan_chen Thursday, December 29, 2011 6:12 AM
    Friday, December 23, 2011 8:58 AM
  • You need a stored procedure that accepts nullable/optional parameters for e.g.

    CREATE PROCEDURE TestProc
    (
        @Param1 varchar(50) = NULL,
        @Param2 varchar(50) = NULL,
        @Param3 varchar(50) = NULL
    )

    then update your edmx


    • Marked as answer by Alan_chen Thursday, December 29, 2011 6:12 AM
    Friday, December 23, 2011 9:13 AM

All replies

  • This forum supports .NET Framework setup and installation.

    For best answers to your SQL Server stored procedure question, I suggest you ask here:

    http://social.msdn.microsoft.com/Forums/en-US/category/sqlserver


    • Edited by pvdg42 Tuesday, December 20, 2011 1:38 AM
    Friday, December 16, 2011 1:35 PM
  • Hi Karthika,

    You should provide Override method for the Import function to provide the default values for other parameters by yourself.

    public int fnCreateContact(int param1,int param2,int param3)
    {
    return  fnCreateContact(int param1,int param2,int param3,........);
    
    }
    

    Like this.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Alan_chen Thursday, December 29, 2011 6:12 AM
    Tuesday, December 20, 2011 8:42 AM
  • I am not asking stored procedure. I am asking how to use entity framework with passing few parameter values instead of passing all parameter value.
    Friday, December 23, 2011 8:48 AM
  • Hi PM,

    The method will created based on your Stored Procedure, there is no way to customize this method, the only way is overload the method, thanks for understanding.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Alan_chen Thursday, December 29, 2011 6:12 AM
    Friday, December 23, 2011 8:58 AM
  • You need a stored procedure that accepts nullable/optional parameters for e.g.

    CREATE PROCEDURE TestProc
    (
        @Param1 varchar(50) = NULL,
        @Param2 varchar(50) = NULL,
        @Param3 varchar(50) = NULL
    )

    then update your edmx


    • Marked as answer by Alan_chen Thursday, December 29, 2011 6:12 AM
    Friday, December 23, 2011 9:13 AM
  • You need a stored procedure that accepts nullable/optional parameters for e.g.

    CREATE PROCEDURE TestProc
    (
        @Param1 varchar(50) = NULL,
        @Param2 varchar(50) = NULL,
        @Param3 varchar(50) = NULL
    )

    then update your edmx


    This does not work. The imported Stored procedure still requires that a parameter be set for it.

    Edward R. Joell MCSD MCDBA

    Monday, February 23, 2015 9:25 PM
  • Hi Karthika,

    You should provide Override method for the Import function to provide the default values for other parameters by yourself.

    public int fnCreateContact(int param1,int param2,int param3)
    {
    return  fnCreateContact(int param1,int param2,int param3,........);
    
    }
    

    Like this.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    But what happens when the model gets updated from the database? Do you have to rewrite all of your overloads?

    Edward R. Joell MCSD MCDBA

    Monday, February 23, 2015 9:27 PM