Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is there no SingleOrDefaultAsync for IQueryables?

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.

like image 693
Ingmar Avatar asked Jun 17 '14 09:06

Ingmar


2 Answers

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.

like image 138
Sergey Berezovskiy Avatar answered Sep 21 '22 13:09

Sergey Berezovskiy


I fixed it by adding using Microsoft.EntityFrameworkCore;

like image 28
mdatsev Avatar answered Sep 22 '22 13:09

mdatsev