How to check whether an entity is already tracked by the DbContext before attaching it in EF Core
Use DbSet.Local.FindEntry(key) to ask the change tracker whether an entity with a given key is tracked, without a database round trip or a scan. Why Entry(entity).State lies for this question, why Find queries, and a tested AttachOrMerge helper for EF Core 10.