Member 13902193 Ответов: 0

В mvc4 я возвращаю хранимую процедуру для повторного вызова userid, examid и questionid, но я хочу, чтобы код контроллера вызывал этот sp, как это делается


ALTER procedure [dbo].[Usp_sel_Result] 2,4019,2027
  @Userid int =null,
  @QuestionId int=null,
  @ExamId int =null
As
begin
  SELECT  [UserId]
    ,[QuestionId]
    ,[ExamId]
    ,[QuestionName]
    ,[OptionOne]
    ,[OptionSecond]
    ,[OptionThird]
    ,[OptionForth]
    ,[TrueAnswer],
    convert(int, [dbo].UserAnswer.[YourAnswer]) as [YourAnswer],
    convert(int, 0) as score,
    convert(int, 0) as totalscore
  INTO #tmp 
  FROM [dbo].UserAnswer
  where 
    CASE WHEN isnull(@UserId, 0) = 0		
      THEN 0 
      ELSE [dbo].UserAnswer.UserId 
    END = isnull(@UserId, 0) 
    AND CASE WHEN isnull(@ExamId, 0) = 0
      THEN 0 
      ELSE [dbo].UserAnswer.ExamId 
    END = isnull(@ExamId, 0) 
 
  update  #tmp
  set score = 1
  where [TrueAnswer] = [YourAnswer]

  ----select * from #tmp

  declare @totalscore int

  select @totalscore = sum(#tmp.score) from #tmp 

  update  #tmp
  set totalscore = @totalscore

  select * from #tmp

END


Что я уже пробовал:

var score = db.sel_Result(UserId, QuestionId, ExamId);
ViewBag.totalscore = score;
var score = db.sel_Result(i => new { i.UserId, i.QuestionId, i.ExamId }).ToList());

0 Ответов