question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support ContainsKey (as an analyzer is telling us to use it)

See original GitHub issue

What problem are you trying to solve? After recently upgrading to .NET 6, there’s a new analyzer prompting you to convert dict.Keys.Contains("foo") to dict.ContainsKey("foo"), but that’s not supported by EF Core, so a quick refactor can have nasty consequences.

Describe the solution you’d like Can dict.ContainsKey be supported?

I could probably help out with some direction.

(didn’t see any previous issues actually ask for this, sorry if it’s been previously rejected)

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
rojicommented, Dec 2, 2021

Triage decision: translating ContainsKey as above is something that is hard for EF Core to support in an efficient way. We will consider adding a diagnostics suppressor to suppress this warning when it appears inside an EF Core LINQ query (best effort). This would depend on having infrastructure for identifying EF Core LINQ queries at compile-time, which we don’t currently have.

0reactions
JustArchicommented, May 24, 2022

The issue seems to be pretty old but I’ve stumbled upon this just today as well. I’d have expected dictionary.ContainsKey(x) to be internally handled the same as dictionary.Keys.Contains(x). If this is not possible to do in an efficient way, CA1841 should take it into account when inside EF LINQ query.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dictionary<TKey,TValue>.ContainsKey(TKey) Method
It also shows how to use the TryGetValue method to retrieve values, which is an efficient way to retrieve values when a program...
Read more >
How can the containsKey() method of a Java Hash Table ...
A string that you put into a hashtable isn't stored at the ... So you see that an array can find things fast...
Read more >
Why does java.util.Map.containsKey throw a null pointer ...
1. You use containsKey on a map that supports a null key. As the user of this function you expect to get either...
Read more >
PVS-Studio evolution: data flow analysis for related variables
Our clients write us about their issues — we do everything to make PVS-Studio better. And such articles help us to tell the...
Read more >
HashMap containsKey() Method in Java
It takes the key element as a parameter and returns True if that element is mapped in the map. Syntax: Hash_Map.containsKey(key_element).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found