Just finished writing a small app that needed to import non-keyed data into a keyed table. To do that, I needed to import only unduplicated data. So, I used EF to manage the target database.

The target table in the database is named Address. When adding a new row I first need to check in the context.Addresses collection for a duplicate.

I was getting missed duplicates when simply querying against context.Addresses. After a lot of digging in the debugger, I found that the duplicate record was in context.Addresses.Local, but not in context.Addresses. So, checking both collections finds all the duplicates. Very frustrating.