I am trying to call a stored procedure from Entity Framework in the following way:
Context.Database.SqlQuery<int>(sqlSP, params).FirstOrDefault();
but I get this error:
The data reader has more than one field. Multiple fields are not valid for EDM primitive or enumeration types
With LinqPad you can see that the stored procedure is working
The generated code from LinqPad for the same call in SQL is the following
-- Region Parameters
DECLARE @RETURN_VALUE Int
DECLARE @contenttype VarChar(50) = ''
DECLARE @image VarBinary(1000) = null
DECLARE @applicationid Int = 81725
DECLARE @statusid Int = 10
DECLARE @notes VarChar(1000) = ''
DECLARE @requestuserid Int = 59
DECLARE @assigneduserid Int = 655
DECLARE @parentid Int = 0
DECLARE @eventid Int = 0
DECLARE @discipline Int = 5
DECLARE @replyby DateTime = '2017-09-14 16:22:40.082'
DECLARE @workitemid Int = 81725
DECLARE @messagetype Int = 2
DECLARE @inspectionid Int = 6081
DECLARE @floor SmallInt = 3
-- EndRegion
exec @RETURN_VALUE = [dbo].[usp_InsertInspectionEventPublic] @contenttype, @image, @applicationid, @statusid, @notes, @requestuserid, @assigneduserid, @parentid, @eventid, @discipline, @replyby, @workitemid, @messagetype, @inspectionid, @floor
The stored procedure always returns an id in the following way:
select @id = SCOPE_IDENTITY() from TEMPTABLE
Return @id
I tried this too:
var returnCode = new SqlParameter("@ReturnCode", SqlDbType.Int);
returnCode.Direction = ParameterDirection.ReturnValue;
var sql = "exec @ReturnCode =dbo.usp_insertinspectioneventpublic @contenttype, @image, @applicationid, @statusid, @notes, @requestuserid, @assigneduserid, @parentid, @eventid, @discipline, @replyby, @workitemid, @messagetype, @inspectionid, @floor";
var data = Context.Database.SqlQuery<int>(sql, returnCode, inParameters);
var res = data.FirstOrDefault();
return res;
But I am getting another error with that approach: When executing a command, paramerters must be exclusively database parameters or values. Which can be the problem here?

ReturnValuefromparams(which is a keyword so don't use it)