/// <summary>
 /// Creates a new entity graph for the given entity and shape and stores it in the
 /// cache, or returns the graph from the cache if it is already present there.
 /// </summary>
 /// <param name="entity"></param>
 /// <param name="shape"></param>
 /// <returns></returns>
 protected EntityGraph <TEntity> GetOrCreate(TEntity entity, IEntityGraphShape shape)
 {
     {
         int           key       = entity.GetHashCode() ^ shape.GetHashCode();
         WeakReference reference = null;
         if (_entityGraphs.ContainsKey(key) == false)
         {
             reference = new WeakReference(null);
             _entityGraphs.Add(key, reference);
         }
         else
         {
             reference = _entityGraphs[key];
         }
         if (reference.Target == null)
         {
             reference.Target = Create(entity, shape);
         }
         return(_entityGraphs[key].Target as EntityGraph <TEntity>);
     }
 }