I have this code in which I am calling a stored procedure and that stored procedure will return 1 or 0 based upon its execution.
public async Task<int> CreateData(int id, string name)
{
return await _dbContext.Database.ExecuteSqlInterpolated($"execute spname {id}, {name}");
}
Running this code, I get this error:
int does not contain a definition for GetAwaiter
I checked for solution on Google and its saying I need to use .ToListAsync()
at the end of the stored procedure call. But my stored procedure is not returning any list.
Can someone please help?
Thanks in advance.
CodePudding user response:
Using the ExecuteSqlInterpolatedAsync
Method instead of ExecuteSqlInterpolated
should Work.
Or
You can remove the Async
suffix (if you don't need to run the function asynchron) and write your method like this:
public int CreateData(int id, string name)
{
return _dbContext.Database.ExecuteSqlInterpolated($"execute spname {id}, {name}");
}