Why is there no SingleOrDefaultAsync for IQueryables?

别来无恙 提交于 2019-12-23 07:38:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!