问题
The following code does not compile because SingleOrDefaultAsync() is not a suitable extension for GetAppointments(). I was just wondering why ...
public IQueryable<Appointment> GetAppointments()
{
return Context.Appointments;
}
public async Task<Appointment> GetAppointmentAsync(int appointmentId)
{
return await GetAppointments().SingleOrDefaultAsync(a => a.ID == appointmentId);
}
I am using EF 6.0.0. And please ignore what I am doing here exactly. I just tried to make things easier than they actually are in my project.
回答1:
Make sure you have added System.Data.Entity
namespace to your usings. This is an extension method, and it will not be available until you add appropriate namespace.
回答2:
I fixed it by adding using Microsoft.EntityFrameworkCore;
来源:https://stackoverflow.com/questions/24259703/why-is-there-no-singleordefaultasync-for-iqueryables