Skip to content

Analyzer to warn of final select that will retrieve entire entity because of client evaluation #37223

@ghosttie

Description

@ghosttie

What problem are you trying to solve?

If Select refers to a complex property or method, the whole entity is retrieved. It's not always obvious when this is going to happen, and it's easy for developers to miss, which can cause performance problems if the entities are large and/or if there are a lot of them.

For example if we have a User entity with a FirstName and LastName, this query will only retrieve the FirstName and LastName:

await _context.Users
    .Select(u => u.FirstName + " " + u.LastName)
    .ToListAsync();

However if the User class had this property

public string FullName => FirstName + " " + LastName;

then a developer might accidentally use it in a Select, not realizing that it will retrieve the whole entity:

await _context.Users
    .Select(u => u.FullName)
    .ToListAsync();

Describe the solution you'd like

An analyzer to detect this situation and warn the developer

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions