Skip to content

Additional possible diagnostics analyzers/suppressors #22086

Open

Description

@roji

Scenarios requiring identifying EF Core LINQ queries (could use common infrastructure):

One idea here would be to have users tell us in .editorconfig that all queryable LINQ queries are e.g. SQL Server; this would be an opt-in that could unlock provider-specific warnings/code fixes.

See #20206 for previous unanalyzed scenarios.

Activity

  1. added this to the Backlog milestone on Aug 17, 2020
  2. changed the title [-]Analyzer: additional scenarios to be analyzed[/-] [+]Additional possible diagnostics analyzers/suppressors[/+] on Dec 2, 2021
  3. vslee commented on Jan 3, 2023

    @vslee

    composite-issue label? Or is that already implied by User Story?

  4. bricelam commented on May 19, 2023

    @bricelam
    Contributor

    One area I've been thinking we could improve using analyzers is cleaning up people's OnModelCreating code. We've had a few workarounds that later get a better API. I suspect the old workarounds are just sitting around providing bad examples to people.

    For example, the old way to configure precision and scale was using the column type:

    // EF Core 1-4
    modelBuilder.Entity<Entity>()
        .Property(e => e.DecimalProperty)
            .HasColumnType("decimal(18, 2)");

    But in EF Core 5, we added a better way to do it:

    // EF Core 5
    modelBuilder.Entity<Entity>()
        .Property(e => e.DecimalProperty)
            .HasPrecision(18, 2);

    In addition, I think there's an opportunity to discourage people from dropping down to the core metadata APIs. For example, we could also provide a fix for code like this:

    var decimalProperty = modelBuilder.Entity<Entity>().Property(e => e.DecimalProperty).Metadata;
    decimalProperty.SetPrecision(18);
    decimalProperty.SetScale(2);
  5. added
    composite-issue
    on Dec 8, 2023
  6. ranma42 commented on May 5, 2024

    @ranma42
    Contributor

    IIUC now suppressions work as intended even when TreatWarningsAsErrors is set #29582 and efcore contains some infrastructure to identify EF Core LINQ queries (maybe not in all cases, but at least in many relevant cases that are being used to pre-compile queries).
    Is this a good time to try and tackle some of these issues? (given that now there seems to be the infrastructure already in place, would some of these be good first issue candidates?)

  7. roji commented on May 6, 2024

    @roji
    MemberAuthor

    @ranma42 the infrastructure introduced for identifying EF LINQ queries (for NativeAOT/precompiled queries) is very new, and is currently not being used in a Roslyn analyzer/source generator at all (but rather in a custom step, meant to be executed outside Roslyn at publish-time). So in theory you're absolutely right, and this does open up a future where we can start emitting/suppressing diagnostics inside LINQ queries; but in practice, it will take a while before this is something that we're able to tackle.

    In any case, I definitely wouldn't consider any analyzer feature as a good first issue; writing analyzers/suppressors correctly (and efficiently!) can be quite tricky/advanced.

  8. added theissue type on Jun 15, 2025
  9. changed the issue type fromtoon Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-analyzercomposite-issue

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions