getting a single value from entity framework core stored procedure
Dec 31, 2020 03:22 AM|anjaliagarwal5@yahoo.com|LINK
Hello All,
I am trying to call a stored procedure using entity framework core. The stored procedure is little bit complicated so I am not using LINQ. Below is my code:
using(IdentityProofContext dc = new IdentityProofContext())
{
SqlParameter[] @params =
{
new SqlParameter("@result", SqlDbType.Int) {Direction = ParameterDirection.Output}
};
dc.IdentityPersonalData.FromSqlRaw("Execute usp_GetIdentityProofStatus", @params).FirstOrDefaultAsync();
var result1 = dc.IdentityPersonalData.FromSqlInterpolated($"EXEC usp_GetStatus").ToListAsync().Result;
//var result = @params[0].Value;
//if (result > 0)
//{
// MiscEmails.sendEmails();
//}
below is my stored procedure:
alter Procedure usp_GetStatus
(
@result int OUTPUT
)
AS
SELECT @result = COUNT(*)
FROM dbo.TestData
WHERE DATEDIFF(MINUTE, DateInserted, GETDATE()) < 120 --Number of minutes
AND STATUS IN ('test1' )
return @result
These are the two different lines of code that I am trying , I am using to call the stored procedure and both of them are throwing exception.
dc.IdentityPersonalData.FromSqlRaw("Execute usp_GetIdentityProofStatus", @params).FirstOrDefaultAsync(); var result1 = dc.IdentityPersonalData.FromSqlInterpolated($"EXEC usp_GetIdentityProofStatus").ToListAsync().Result;
Member
511 Points
1273 Posts
getting a single value from entity framework core stored procedure
Dec 31, 2020 03:22 AM|anjaliagarwal5@yahoo.com|LINK
Hello All,
I am trying to call a stored procedure using entity framework core. The stored procedure is little bit complicated so I am not using LINQ. Below is my code:
below is my stored procedure:
These are the two different lines of code that I am trying , I am using to call the stored procedure and both of them are throwing exception.
any help will be highly appreciated.