calling a stored procedure using entity relationship RRS feed

  • Question

  • User351619809 posted

    Hi All,

    I created a stored procedure that accepts three parameters and it also has some dynamic query in it too. How can I call this stored procedure in my asp.net application using entity relationship.

    any help will be appreciated.

    Tuesday, April 11, 2017 12:21 AM


All replies

  • User705563967 posted

    there is many way to achieve this one of them Is shown below.

     SqlParameter param1 = new SqlParameter("@name", "test");
     SqlParameter param2 = new SqlParameter("@type", "testtype");
     var query = db.Database.SqlQuery<employee>("GetAllName @name,@type", param1,param2);


    the employee is return type of model if it is not belong to any model then you need to create viewmodel with the same name
    that storeprocedure returns


    var result=db.Database.SqlQuery<ProjectsModel>("GetProjectDetails @sectorId,@subSectorId", 
    						  new Object[] { new SqlParameter("@sectorId", sectorid),
    				                 new SqlParameter("@subSectorId", subsectorid)}

    Tuesday, April 11, 2017 5:20 AM
  • User-1838255255 posted

    Hi anjaliagarwal@yahoo.com,

    According to your description, as far as I know, you could define stored producer, you can use stored procedures either to get the data or to add/update/delete the records to one or multiple database tables.

    For more details, please check the following complete tutorials:

    Stored Procedure in Entity Framework:


    Entity Framework: Call Stored Procedure with Parameters using C# and VB.Net:


    Best Regards,

    Eric Du

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 11, 2017 7:53 AM