C# 只能通过RowsAffectedParameter属性映射输出参数

C# 只能通过RowsAffectedParameter属性映射输出参数,c#,entity-framework,stored-procedures,entity-framework-6,C#,Entity Framework,Stored Procedures,Entity Framework 6,我有一个存储过程,在这个存储过程中,我希望返回输出值并在通过实体框架访问它的应用程序上访问它 我的存储过程: ALTER Procedure [dbo].[Insert_StudentDetails] ( @Name varchar(150), @City varchar(150), @ReturnValue int OUT ) as Begin --Declare if NOT exists(Select Name from Student

我有一个存储过程,在这个存储过程中,我希望返回输出值并在通过实体框架访问它的应用程序上访问它

我的存储过程:

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 Name=@Name    
    AND City=@City)
    begin
    Insert into Student(Name, City)
    values(@Name, @City)        
    set @ReturnValue=1
    end
    else
    begin
    set @ReturnValue=0
    end
    select @ReturnValue
End
select @ReturnValue= SCOPE_IDENTITY()
现在,右键单击edmx文件中的表格后,显示如下:

当我导入函数时,我选择none作为回报

我通过以下代码访问它:

 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;
            }
        }
    }
运行时,它显示以下异常:

在错误列表中,以下异常也将出现:

对。我解决了

我更改了存储过程的最后一行:

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 Name=@Name    
    AND City=@City)
    begin
    Insert into Student(Name, City)
    values(@Name, @City)        
    set @ReturnValue=1
    end
    else
    begin
    set @ReturnValue=0
    end
    select @ReturnValue
End
select @ReturnValue= SCOPE_IDENTITY()
在更新模型之后,在映射部分,我只是将结果列绑定中的ReturnValue添加到。只需在写入输出值后点击回车按钮。请勾选out值旁边的复选框