It looks to me like the following condition on line 128 will always be true as FindEntityByKey will ask the context for the matching entity, if it's not in the context's local collection it will then hit the db to get the entity. Considering we are working with associated entities they should be in the database so will always return on line 129.

I think the intended purpose is to check the context.Set(type).Local collection doesn't contain an entity with the same key?