Skip to content

Add analyzer to guard against ToAsyncEnumerable VS AsAsyncEnumerable #37670

@Dreamescaper

Description

@Dreamescaper

What problem are you trying to solve?

Today I've encountered the following code:

        var results = context.Entities
            .Where(o => blablalba))
            .ToAsyncEnumerable();

        await foreach (var chunk in results.Chunk(100))
        {
             // DoSmthAsync in chunks
        }

It looks perfectly fine on first glance, but it, if fact, has an issue - ToAsyncEnumerable works on IEnumerable argument, and it causes sync iteration over IQuearyble.
It should've been AsAsyncEnumerable instead.

Describe the solution you'd like

Add analyzer to warn against ToAsyncEnumerable usage on IQueryable, and suggest to use AsAsyncEnumerable instead.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions