Skip to content

Document LINQ provider and EF Core translation suppression guidance for CA1847 (Fixes #48694) - #56681

Open
Manish-1kumar wants to merge 1 commit into
dotnet:mainfrom
Manish-1kumar:users/manish/issue-48694-ca1847-efcore-linq-suppression
Open

Manish-1kumar wants to merge 1 commit into
dotnet:mainfrom
Manish-1kumar:users/manish/issue-48694-ca1847-efcore-linq-suppression

Conversation

@Manish-1kumar

@Manish-1kumar Manish-1kumar commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Addresses issue #48694 by updating the When to suppress warnings guidance in CA1847 (Use String.Contains(char) instead of String.Contains(string) with single characters):

  • Added explicit guidance for developers querying databases via Entity Framework Core (EF Core) or other LINQ providers.
  • Clarified that in expression trees translated to SQL, some LINQ providers cannot translate String.Contains(char) and throw an InvalidOperationException at run time, making suppression of CA1847 appropriate in LINQ query contexts.
  • Linked to the official EF Core translation documentation (aligning with similar guidance in CA1862).

Fixes #48694.


Internal previews

File Preview link
docs/fundamentals/code-analysis/quality-rules/ca1847.md Learn preview

Build report

@dotnetrepoman dotnetrepoman Bot added this to the November 2026 milestone Nov 1, 2026
@dotnet-policy-service dotnet-policy-service Bot added dotnet-fundamentals/svc community-contribution Indicates PR is created by someone from the .NET community. labels Nov 1, 2026
@Manish-1kumar
Manish-1kumar force-pushed the users/manish/issue-48694-ca1847-efcore-linq-suppression branch from f17272d to bbce70c Compare November 30, 2026 17:40
@BillWagner
BillWagner requested a balanced review from Copilot December 1, 2026 17:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The article’s ms.date remains 11/13/2026 and should be updated to reflect the substantive technical guidance added.

1 open issue
What changed in this PR

Updates CA1847 suppression guidance to address issue #48694 and explain LINQ provider translation limitations.

Changes:

  • Adds guidance for EF Core and other LINQ providers that cannot translate String.Contains(char) to SQL.
  • Explains the potential runtime exception and links to EF Core translation documentation.
File Description
docs/​fundamentals/​code-analysis/​quality-rules/​ca1847.md Expands suppression guidance for database queries and adds an EF Core reference.

Review effort: Balanced

Suppress a violation of this rule if you're not concerned about the performance impact of the search invocation in question.
It's safe to suppress a violation of this rule if you're not concerned about the performance impact of the search invocation in question.

If you're using Entity Framework Core (EF Core) or other LINQ providers, you should suppress this rule for scenarios where you query a database using `string.Contains(string)` in an expression tree. Some LINQ providers cannot translate <xref:System.String.Contains(System.Char)?displayProperty=nameWithType> to SQL, throwing an <xref:System.InvalidOperationException> at run time. For more information, see [Translation of built-in .NET string operations](/ef/core/miscellaneous/collations-and-case-sensitivity#translation-of-built-in-net-string-operations).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Indicates PR is created by someone from the .NET community. dotnet-fundamentals/svc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use of Contains() as LINQ query with Entity Framework

2 participants