public EfMatcher(EfMatcherConfig <TInLeft, TEntity, TCtx, TKey> config) { _getFullDataset = config.GetFullDataset; _createIfNotFound = config.CreateIfNotFound; _includeInstruction = config.IncludeInstruction; Context = config.Context; _getLeftKey = config.LeftKeyExpression.Compile(); _getRightKey = config.RightKeyExpression.Compile(); _matchCriteriaBuilder = MatchCriteriaBuilder.Create(config.LeftKeyExpression, config.RightKeyExpression, config.DefaultDatasetCriteria); if (config.GetFullDataset) { var query = (_includeInstruction == null ? config.Context.Set <TEntity>() : _includeInstruction(config.Context.Set <TEntity>())); if (config.DefaultDatasetCriteria != null) { query = query.Where(config.DefaultDatasetCriteria); } var defaultCache = query.ToList(); _cacheSize = Math.Max(defaultCache.Count, config.MinCacheSize); _cachedEntities = defaultCache .Select(i => new { Key = _getRightKey(i), Value = new CachedEntity(i) }) .Where(i => i.Key != null) .ToDictionary(i => i.Key, i => i.Value); } else { _cacheSize = config.MinCacheSize; } }
public EfMatcher(EfMatcherConfig <TInLeft, TEntity, TKey> config) { _getFullDataset = config.GetFullDataset; _createIfNotFound = config.CreateIfNotFound; Context = config.Context; _getLeftKey = config.LeftKeyExpression.Compile(); _getRightKey = config.RightKeyExpression.Compile(); _matchCriteriaBuilder = MatchCriteriaBuilder.Create(config.LeftKeyExpression, config.RightKeyExpression); if (config.GetFullDataset) { var defaultCache = config.Query.ToList(); _cacheSize = Math.Max(defaultCache.Count, config.MinCacheSize); _cachedEntities = defaultCache .Select(i => new { Key = _getRightKey(i), Value = new CachedEntity(i) }) .Where(i => i.Key != null) .GroupBy(i => i.Key) .ToDictionary(i => i.Key, i => i.First().Value, GetEqualityComparer()); } else { _query = config.Query; _cacheSize = config.MinCacheSize; } }