Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

getting a single value from entity framework core stored procedure

$
0
0

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;

any help will be highly appreciated.


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>