BuildYourOwnDAL.SessionLevelCache.TryToFind C# (CSharp) Method

TryToFind() public method

public TryToFind ( Type type, object id ) : object
type System.Type
id object
return object
        public object TryToFind(Type type, object id)
        {
            if (!cache.ContainsKey(type)) return null;

            string idAsString = id.ToString();
            if (!cache[type].ContainsKey(idAsString)) return null;

            return cache[type][idAsString];
        }

Usage Example

Ejemplo n.º 1
0
        private TEntity CreateEntityFromValues <TEntity>(IDictionary <string, object> values)
        {
            var tableInfo = metaDataStore.GetTableInfoFor <TEntity>();

            var cachedEntity = sessionLevelCache.TryToFind(typeof(TEntity), values[tableInfo.PrimaryKey.Name]);

            if (cachedEntity != null)
            {
                return((TEntity)cachedEntity);
            }

            var entity = Activator.CreateInstance <TEntity>();

            Hydrate(tableInfo, entity, values);
            sessionLevelCache.Store(typeof(TEntity), values[tableInfo.PrimaryKey.Name], entity);
            return(entity);
        }