protected override IEnumerable GetEntities(IEnumerable <string> identifiers)
        {
            var identifiersToRequest = identifiers.Except(_savable.GetAllPendingChangesIdentifiers());

            var entities = GetEntitiesFromCache(identifiers);

            return(_savable.CombineWithPendingChanges(entities, _predicate));
        }
        protected override IEnumerable <string> GetIdentifiersToRequest()
        {
            // here we need to get entities from cache, execute the expression on them,
            // get the result and grab only identifiers from the result;

            // read all entites from cache
            var entites = _cachedDataProvider.GetCachedEntities();
            // merge with the all the pending changes
            var mergedEntities    = _savable.CombineWithPendingChanges(entites, null);
            var queryableEntities = mergedEntities.AsQueryable();
            // execute expression on the cached entities
            var newExpressionTree = ModifyExpressionAndReturnResult(_expressionInfo.OriginalExpression, queryableEntities);

            object result;

            if (_expressionInfo.IsEnumerableResult)
            {
                result = queryableEntities.Provider.CreateQuery(newExpressionTree);
            }
            else
            {
                result = queryableEntities.Provider.Execute(newExpressionTree);
            }

            if (result == null)
            {
                return(Enumerable.Empty <string>());
            }

            if (result is T item)
            {
                return new[] { _keyGetter(item) }
            }
            ;

            if (result is IEnumerable <T> items)
            {
                return(items.Select(_keyGetter));
            }

            throw new NotSupportedException($"Expression is not supported");
        }
Пример #3
0
        protected override IEnumerable GetEntities(IEnumerable <string> identifiers)
        {
            var method = _expressionInfo.InnerMostExpression.Method;

            if (!IsNonReplacableMethod(method))
            {
                return(_savable.CombineIdentifiersRangeWithPendingChanges(identifiers, _predicate));
            }

            // non - replacable methods, we need entities
            var identifiersToRequest = identifiers.Except(_savable.GetAllPendingChangesIdentifiers());
            // assume we can just get if from the cache directly for no other properties except key are used.
            var entities = identifiersToRequest.Any() ? _cachedDataProvider.GetCachedEntities(identifiersToRequest) : Enumerable.Empty <T>();

            //var entities = identifiersToRequest.Any() ? _cachedDataProvider.GetEntitiesBasedOnCache(identifiersToRequest) : Enumerable.Empty<T>();

            return(_savable.CombineWithPendingChanges(entities, _predicate));
        }
Пример #4
0
        protected override IEnumerable GetEntities(IEnumerable <string> identifiers)
        {
            IEnumerable <T> entities;

            if (identifiers == null)
            {
                entities = GetAllEntitiesFromDao();
            }
            else if (!identifiers.Any())
            {
                entities = Enumerable.Empty <T>();
            }
            else
            {
                var identifiersToRequest = identifiers.Except(_savable.GetAllPendingChangesIdentifiers());
                entities = identifiersToRequest.Any() ? GetEntitiesFromDao(identifiersToRequest) : Enumerable.Empty <T>();
            }

            return(_savable.CombineWithPendingChanges(entities, _predicate));
        }