0

我有一個存儲過程,我想在該存儲過程中返回輸出值,並在我通過實體框架訪問它的應用程序上訪問它。只能通過RowsAffectedParameter屬性映射輸出參數

我的存儲過程:

ALTER Procedure [dbo].[Insert_StudentDetails] 
(
    @Name varchar(150), 
    @City varchar(150), 
    @ReturnValue int OUT 
) 

as 
Begin 
    --Declare 
    if NOT exists(Select Name from Student 
    WHERE [email protected]  
    AND [email protected]) 
    begin 
    Insert into Student(Name, City) 
    values(@Name, @City)   
    set @ReturnValue=1 
    end 
    else 
    begin 
    set @ReturnValue=0 
    end 
    select @ReturnValue 
End 

現在後右鍵點擊EDMX文件中的表格它顯示爲以下幾點:

enter image description here

當我導入功能,我選擇沒有在返回。

我通過下面的代碼訪問它:

public bool insertstudentdata(Student student) 
    { 
     using (CollegeDataEntities context = new CollegeDataEntities()) 
     { 
      ObjectParameter ReturnedValue = new ObjectParameter("ReturnValue", typeof(int)); 
      context.InsertStudentData(student.Name, student.City, ReturnedValue); 
      if (Convert.ToInt32(ReturnedValue) == 1) 
      { 
       return true; 
      } 
      else 
      { 
       return false; 
      } 
     } 
    } 

在運行時,它顯示了以下異常:

enter image description here

錯誤列表,下面的異常也即將:

enter image description here

回答

0

是的。我解決了它。

我改變了我的存儲過程的最後一行:

select @ReturnValue= SCOPE_IDENTITY() 

更新模型後,在映射的一部分,我只是在結果的列綁定到添加的ReturnValue。在寫出輸出值後,只需點擊輸入按鈕。請勾選出相鄰的複選框值

enter image description here