Skip to content

Add ToHashSetAsync() to IQueryable<T> #30033

@wertzui

Description

@wertzui

In current EF Core code, most queries are written like this

List<Blog> blogs = await context.Blogs.Where(b => something).ToListAsync(cancellationToken);

The problem I see with this approach is that List<T> implies an order of the elements, although the database does not guarantee an order as long as there is no OrderBy() in the query.

I know that this pattern is well established and it might be impossible to change it.
However to allow to better express that there is no order, I would like to see another extension method ToHashSetAsync().
Then one could write a query like this

HashSet<Blog> blogs = await context.Blogs.Where(b => something).ToHashSetAsync(cancellationToken);

This would better express that there is no ordering to all consumers of the blogs collection.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions