Skip to content

Indent .ThenInclude() for clearer navigation hierarchy in EF Core queries #1602

@HerrLiljegren

Description

@HerrLiljegren

Suggestion: Improve formatting of chained .Include() and .ThenInclude() in EF Core queries

When using Entity Framework Core, readability is greatly improved by clearly indicating navigation relationships. Currently, CSharpier formats chained .Include() and .ThenInclude() methods without indentation differentiation, which can obscure their relationship.

The additional indentation on .ThenInclude() visually represents the hierarchy and makes the code clearer at a glance.

Input:

var user = context.Users.Include(u => u.Orders).ThenInclude(o => o.OrderItems).Where(u => u.Id == userId).FirstOrDefault();

Output:

var user = context.Users
    .Include(u => u.Orders)
    .ThenInclude(o => o.OrderItems)
    .Where(u => u.Id == userId)
    .FirstOrDefault();

Expected behavior:

var user = context.Users
    .Include(u => u.Orders)
        .ThenInclude(o => o.OrderItems)
    .Where(u => u.Id == userId)
    .FirstOrDefault();

The additional indentation on .ThenInclude() visually represents the navigation hierarchy clearly.


Would this be something worth considering?

And also, thanks for your awesome work!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions