Skip to content

Fix S3358 FP: Suggesting to extract ternary from EF Core select #9801

@grosch-intl

Description

@grosch-intl

Description

The below code is not able to have the ternary operator extracted as it's part of a linq query, so the whole thing has to be run against each record.

Reproducer

        var query = context.Checklist
            .AsNoTracking()
            .Where(...)
            .Select(x => new {
                ReviewStatus = x.ReviewApprovedUtc.HasValue ? "Approved" : x.ReviewRejectedUtc.HasValue ? "Rejected" : x.ReviewRequestedUtc.HasValue ? "Pending" : null,              

Product and Version

SonarAnalyzer.CSharp 10.23.0.137933

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions