dotnet / fsharp

The F# compiler, F# core library, F# language service, and F# tooling integration for Visual Studio
https://dotnet.microsoft.com/languages/fsharp
MIT License
3.91k stars 785 forks source link

Query builder throws error when using ToListAsync in combination with EF Core DbSet #16503

Open KenBonny opened 10 months ago

KenBonny commented 10 months ago

I'm writing a POC to see how viable F# is for our new project. I have set up an in memory database with EF Core, as I want to give the current developers some points of recognition while highlighting some interesting new ways of doing things. One of those things is to use a query builder. When I use my db.Drones to get all the drones and I call Seq.toList, it all works fine. When I instead use EntityFrameworkQueryableExtensions.ToListAsync I get the error InvalidOperationException: The source 'IQueryable' doesn't implement 'IAsyncEnumerable<Drone.Api.Features.GetDrones+DroneDto>'.

Working version:

query {
    for drone in context.Drones do
    select {
        Make = drone.Make
        Model = drone.Model
    }
} |> Seq.toList

Version that throws error:

open Microsoft.EntityFrameworkCore
query {
    for drone in context.Drones do
    select {
        Make = drone.Make
        Model = drone.Model
    }
} |> EntityFrameworkQueryableExtensions.ToListAsync

Expectation: A way to query my database in an async manner.

0101 commented 9 months ago

query doesn't support async enumeration by itself, it just returns IQueryable which contains the query.

It's hard to say what exactly is ToListAsync trying to do with it. This should probably be raised with @dotnet/efteam to clarify.