I have created one .NET Core API , where my all methods are asynchronous but there is one requirement like GetBalance()
which just return one entity (record) only.
I am not able to using SingleOrDefaultAsync()
, getting error like does not contain a definition for this.
I am using simple basic EF Code First approach with no Repository pattern.
Here is my code example.
public async Task<ResponseBalanceModel> GetBalanceFor(int accountNumber)
{
var result = await _dbContext.Accounts.Where(x =>
x.AccountNumber == accountNumber)
.SingleOrDefaultAsync(); // this is not working.
/*Below tried code are not working.
var result1 = await _dbContext.Accounts.Where(x => x.AccountNumber == accountNumber).SingleOrDefaultAsync();
var result2 = await _dbContext.Accounts.FirstOrDefaultAsync(x => x.AccountNumber == accountNumber);
*/
}
For more clarification
Reference of Entityframework in my project. (.NET Core)
The EF Core async extension methods are defined in the Microsoft.EntityFrameworkCore namespace. This namespace must be imported for the methods to be available.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With