how to call stored procedure in EF6 with output parameters entity-framework-6 output-parameter stored-procedures string


i have a stored procedure which returns a parameter containing string in it i don't know how to call it and get the output parameter to show on my view

ALTER PROCEDURE [dbo].[sp_test]
@room_type varchar(40)
,@room_price_min float
,@room_price_max    float
,@room_number   varchar(30)
,@new varchar(50) output
--select @room_no 
if exists(select room_number from Rooms_ms where room_number=@room_number) 
    set @new='Room Already Exists'
    select @new

insert into Rooms_ms(room_type,room_price_min,room_price_max,room_number) values

set @new='Successfully'
select  @new

I'm trying to catch it like below but don't know how to exactly do it.

 var result=   db.sp_test(a, b, 0, c);

Thank you

7/8/2017 10:30:32 AM

Accepted Answer

You can implement the following to retrieve the data for a stored procedure call

using(var db = new iConext())
   var details = db.Database.SqlQuery<iType>("exec iProc @param", new SqlParameter("@param", iValue));
  • iType is int or string or long or can be a ComplexType
  • @param is one or more required parameters
  • iContext is for your db connection
7/8/2017 1:20:37 PM

Popular Answer

It is one of sample my code

string sql = string.Format("exec sp_MyTest '" + methods.DateTimeFormat(vmodel.Search.FDate, false, 1) + "','" + methods.DateTimeFormat(vmodel.Search.TDate, false, 1) + "','" + vmodel.Search.LocationId + "',"+ 0"'");

var result = db.(DbSetName(like.Students))SqlQuery(sql).ToString();

if Return List, then 
    var result = db.(DbSetName(like.Students))SqlQuery(sql).ToList();

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow