OK looking for some remote paired-programming today. Want to get someone to chat with about Entity Framework Core 3.1 Explicitly Compiled Queries. They were very simple in EFCore 2.X but now are tricky w/ IAsyncEnumerable. Anyone want to help?
EF Core version: 3.1
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET Core 3.1
@roji @AndriySvyryd @maumar Could one of you help Chris with this since @smitpatel is out?
@cwoodruff Can you post an outline of what you are trying? People are busy or out today, and we may need Smit, but if you post something we'll take a look when we can.
@ajcvickers I have a repo with all of the code located for both sync and async. The sync code (master branch) works and uses compiled queries. The second branch (async_compiled_queries) is my attempt to move to use async compile queries. This branch does not work and I am trying to learn how to use IAsyncEnumerable correctly.
master branch --> https://github.com/cwoodruff/ChinookASPNETCore3APINTier
async_compiled_queries branch --> https://github.com/cwoodruff/ChinookASPNETCore3APINTier/tree/async_compiled_queries
NOTE -- The master branch has 2 data access projects: "Chinook.DataEFCore" project is not using compiled queries and "Chinook.DataEFCoreCmpldQry" project uses sync compiled queries.
NOTE -- I only have 1 data access project in the async_compiled_queries branch that uses async compiled queries called "Chinook.Data"
@cwoodruff As I said before, I'm not an expert in this area, but I think the issue is that the code is trying to return Tasks of IAsyncEnumable. Instead, just use the unwrapped IAsyncEnumable and then either use await foreach or something like await ToListAsync() to get the results.
For example, for GetAllAlbums I did this:
```C#
private static readonly Func
EF.CompileAsyncQuery((ChinookContext db) => db.Album);
public IAsyncEnumerable
then in the repository:
```C#
public IAsyncEnumerable<Album> GetAll() => _context.GetAllAlbums();
and in the test:
C#
var albums= await _repo.GetAll().ToListAsync();
This worked for me when hacking at the code you posted. Hope it helps.
Follow-up question: have you seen real applications using EF Core where explicitly compiling the queries makes a big difference? My expectation is that in most cases just letting EF auto-compile has good enough perf.
Most helpful comment
@cwoodruff As I said before, I'm not an expert in this area, but I think the issue is that the code is trying to return Tasks of
IAsyncEnumable. Instead, just use the unwrappedIAsyncEnumableand then either useawait foreachor something likeawait ToListAsync()to get the results.For example, for GetAllAlbums I did this:
```C#> _queryGetAllAlbums =
private static readonly Func
EF.CompileAsyncQuery((ChinookContext db) => db.Album);
public IAsyncEnumerable GetAllAlbums() => _queryGetAllAlbums(this);
and in the test:
C# var albums= await _repo.GetAll().ToListAsync();This worked for me when hacking at the code you posted. Hope it helps.
Follow-up question: have you seen real applications using EF Core where explicitly compiling the queries makes a big difference? My expectation is that in most cases just letting EF auto-compile has good enough perf.