private static void RemoveFromEntityCache(ICacheable entity) { var type = entity.GetRealType(); if (EntityCache.ContainsKey(type)) { if (EntityCache[type].ContainsKey(entity.Id)) { var ce = EntityCache[type][entity.Id]; ce.Workspace.Dispose(); EntityCache[type].Remove(ce.Cacheable.Id); } } }