Nilesh
Nilesh

Reputation: 628

How to solve error int does not contain a definition for GetAwaiter .NET Core Web API

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.

Upvotes: 0

Views: 519

Answers (1)

Leppin
Leppin

Reputation: 241

Using the ExecuteSqlInterpolatedAsync Method instead of ExecuteSqlInterpolated should Work.

https://learn.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.relationaldatabasefacadeextensions.executesqlinterpolatedasync?view=efcore-6.0

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}");                      
}

Upvotes: 3

Related Questions