Skip to content

Weird Formatting of LINQ/Entity Framework Chains #1676

@sblmnl

Description

@sblmnl

Related to #1130. This is a particular nuisance when using Entity Framework where all of the collections are nested within a DbContext instance.

The current behavior violates the general "one dot per line" rule. Additionally, this is the primary reason that I have not introduced CSharpier into my team's project.

Input:

public List<ThingDto> GetThingsCreatedAtOrAfter(DateTimeOffset timestamp)
{
    return _db.Things.Where(x => x.CreatedAt >= timestamp).Select(x => new ThingDto
    {
        Id = x.Id,
        Name = x.Name,
        Description = x.Description,
        Quantity = x.Quantity,
    }).ToList();
}

Output:

public List<ThingDto> GetThingsCreatedAtOrAfter(DateTimeOffset timestamp)
{
    return _db
        .Things.Where(x => x.CreatedAt >= timestamp)
        .Select(x => new ThingDto
        {
            Id = x.Id,
            Name = x.Name,
            Description = x.Description,
            Quantity = x.Quantity,
        })
        .ToList();
}

Expected behavior:

public List<ThingDto> GetThingsCreatedAtOrAfter(DateTimeOffset timestamp)
{
    return _db.Things
        .Where(x => x.CreatedAt >= timestamp)
        .Select(x => new ThingDto
        {
            Id = x.Id,
            Name = x.Name,
            Description = x.Description,
            Quantity = x.Quantity,
        })
        .ToList();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions