dotnet / dotnet/EntityFramework.Docs
scary number of analyzer warnings on EF samples
- Dominant language
- Mermaid
- Stars
- 1.7k
- Forks
- 2k
- Avg merge
- 7d 23h
- Merged PRs (30d)
- 16
Description
FYI there are 90 individual projects in the EntityFramework.Docs\samples\core, but the [Samples.sln](https://github.com/dotnet/EntityFramework.Docs/blob/main/samples/core/Samples.sln) only contains 85 projects. The missing projects are
- EFGetStarted.Android
- EFGetStarted (Xamarin)
- EFGetStarted.iOS
- GetStartedWinForms
- GetStartedWPF
which should probably be included (for reader interest and to ensure CI testing).
VS analyzers (plus my favourite Roslynator.Analyzers giving RCS1234 messages) spit out an alarming number of Warning/Messages
which is not a happy UX for those of nervous disposition.
Inevitably some are new .NET 8.0 and C# v11 magic (like "**Use primary constructor**"), but there are many ".. **can be simplified**" that suggests the EF samples are lagging behind reasonable professional dev progress and expectation
| num | qty | code | Description |
| - | - | - | - |
| 1 | 138 | **CA1050** | Declare types in namespaces (cf **RCS1110** below) |
| 2 | 7 | CA1806 | 'Split_query_for_non_navigation_collections' calls 'ToList' but does not use the value the method returns. |
| 3 | 5 | CA1816 | Change PublicPooledDbContextFactorySample.SomeDbContext.Dispose() to call GC.SuppressFinalize(object). |
| 4 | 33 | CA1822 | Member 'LoadEntities' does not access instance data and can be marked as static |
| 5 | 14 | CA1826 | Do not use Enumerable methods on indexable collections. Instead use the collection directly. |
| 6 | 1 | CA1829 | Use the "Count" property instead of Enumerable.Count() |
| 7 | 6 | CA1845 | Use span-based 'string.Concat' and 'AsSpan' instead of 'Substring' |
| 8 | 2 | CA1847 | Use 'string.Contains(char)' instead of 'string.Contains(string)' when searching for a single character |
| 9 | 2 | CA1859 | Change type of variable 'searchIds' from 'System.Collections.Generic.IReadOnlySet' to 'System.Collections.Generic.HashSet' for improved performance |
| 10 | 3 | CA1860 | Prefer comparing 'Count' to 0 rather than using 'Any()', both for clarity and for performance |
| 11 | 19 | CA1861 | Prefer 'static readonly' fields over constant array arguments if the called method is called repeatedly and is not mutating the passed array |
| 12 | 1 | CA1862 | Prefer using 'string.Equals(string, StringComparison)' to perform a case-insensitive comparison |
| 13 | 13 | CA1866 | Use 'string.StartsWith(char)' instead of 'string.StartsWith(string)' when you have a string with a single char |
| 14 | 1 | CA1869 | Avoid creating a new 'JsonSerializerOptions' instance for every serialization operation. Cache and reuse instances instead. |
| 15 | 1 | CA2016 | Forward the 'cancellationToken' parameter to the 'SaveChangesAsync' method or pass in 'CancellationToken.None' .. |
| 16 | 1 | CA2208 | Call the ArgumentOutOfRangeException constructor that contains a message and/or paramName parameter |
| 17 | 2 | CA2211 | Non-constant fields should not be visible |
| 18 | 2 | CA2254 | The logging message template should not vary between calls to 'LoggerExtensions.LogInformation(ILogger, EventId, string?, params object?[])' |
| 19 | 1 | EF1002 | Method 'FromSqlRaw' inserts interpolated strings directly into the SQL, without any protection against SQL injection. Consider using 'FromSql' instead |
| 20 | 1 | IDE0025 | Use expression body for property |
| 21 | 2 | IDE0027 | Use expression body for accessor |
| 22 | 171 | IDE0028 | Collection initialization can be simplified |
| 23 | 1 | SIDE0037 | Member name can be simplified |
| 24 | 6 | IDE0040 | Accessibility modifiers required |
| 25 | 2 | IDE0044 | Make field readonly |
| 26 | 1 | IDE0046 | 'if' statement can be simplified |
| 27 | 10 | IDE0051 | Private member 'LaundryBasket._id' is unused |
| 28 | 8 | IDE0052 | Private member 'MyController._context' can be removed as the value assigned to it is never read |
| 29 | 58 | IDE0053 | Use expression body for lambda expression |
| 30 | 15 | IDE0057 | Substring can be simplified |
| 31 | 37 | IDE0060 | Remove unused parameter 'args' if it is not part of a shipped public API |
| 32 | 1 | IDE0061 | Use expression body for local function |
| 33 | 10 | IDE0062 | Local function can be made static |
| 34 | 6 | IDE0063 | 'using' statement can be simplified |
| 35 | 1 | IDE0066 | Use 'switch' expression |
| 36 | 17 | IDE0071 | Interpolation can be simplified |
| 37 | 14 | IDE0079 | Remove unnecessary suppression |
| 38 | 1 | IDE0083 | Use pattern matching |
| 39 | 63 | IDE0090 | 'new' expression can be simplified |
| 40 | 196 | IDE0290 | Use primary constructor |
| 41 | 55 | IDE0300 | Collection initialization can be simplified |
| 42 | 8 | IDE0305 | Collection initialization can be simplified |
| 42 | 8 | IDE1006 | Naming rule violation: Missing prefix: '_' |
| 43 | 40 | RCS1021 | Use expression-bodied lambda |
| 44 | 9 | RCS1036 | Remove unnecessary blank line |
| 45 | **308** | RCS1037 | Remove trailing white-space |
| 46 | 5 | RCS1075 | Avoid empty catch clause that catches System.Exception |
| 47 | 9 | RCS1077 | Optimize LINQ method call |
| 48 | 1 | RCS1084 | Use coalesce expression instead of conditional expression |
| 49 | 3 | RCS1085 | Use auto-implemented property |
| 50 | 207 | RCS1102 | Make class static |
| 51 | 144 | **RCS1110** | Declare 'Program' inside namespace (cf **CA1050** above) |
| 52 | 32 | RCS1118 | Mark local variable as const |
| 53 | 7 | RCS1123 | Add parentheses when necessary |
| 54 | 2 | RCS1146 | Use conditional access |
| 55 | 1 | RCS1155 | Use StringComparison when comparing strings |
| 56 | 1 | RCS1159 | Use EventHandler |
| 57 | 42 | RCS1163 | Unused parameter 'args' |
| 58 | 2 | RCS1166 | Value type object is never equal to null |
| 59 | 2 | RCS1169 | Make field read-only |
| 60 | 60 | RCS1170 | Use read-only auto-implemented property |
| 61 | 37 | RCS1192 | Unnecessary usage of verbatim string literal |
| 62 | 3 | RCS1196 | Call extension method as instance method |
| 63 | 11 | RCS1213 | Remove unused field declaration |
| 64 | 8 | RCS1214 | Unnecessary interpolated string |
| 65 | 2 | RCS1229 | Use async/await when necessary |
| 66 | 19 | RCS1246 | Use element access |
| 67 | 23 | RCS1251 | Remove unnecessary braces |
| 68 | 52 | RCS1261 | Resource can be disposed asynchronously |
| 69 | 1 | SYSLIB1045 | Use 'GeneratedRegexAttribute' to generate the regular expression implementation at compile-time. |
N.B. this is with the standard .editorconfig in the parent folder (so is not anything I have smuggled in with my VS option prefs) !
IMHO the docs should reflect the **latest and greatest guidelines**, and not be tied to backward compat to legacy C# / FW releases
I propose to work up a PR to eliminate/minimise these banshees, unless EF Team declare already on the case to deter me.
Contributor guide
Assessment
This issue has not been assessed yet.