Skip to content

NET-3878 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

    False PositiveRule IS triggered when it shouldn't be.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions