-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Additional possible diagnostics analyzers/suppressors #22086
Comments
|
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); |
IIUC now suppressions work as intended even when |
@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. |
nameof
within raw SQL interpolated strings. This typically happens when people mistakenly want to interpolate column names, but they get parameterized and the query fails.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.
The text was updated successfully, but these errors were encountered: