public OeEfCoreDataAdapter(DbContextOptions options, Cache.OeQueryCache queryCache, OeEfCoreOperationAdapter operationAdapter) : base(queryCache, operationAdapter) { if (options != null) { _dbContextPool = new DbContextPool <T>(options); } }
public static int GetQueryCacheCount(IEdmModel edmModel) { Db.OeDataAdapter dataAdapter = edmModel.GetDataAdapter(edmModel.EntityContainer); Cache.OeQueryCache queryCache = GetQueryCache(dataAdapter); int count = queryCache.CacheCount; foreach (IEdmModel refModel in edmModel.ReferencedModels) { if (refModel.EntityContainer != null) { count += GetQueryCacheCount(refModel); } } return(queryCache.AllowCache ? count : -1); }
private static Expression GetFromCache(OeQueryContext queryContext, T dbContext, Cache.OeQueryCache queryCache, out MethodCallExpression countExpression) { Cache.OeCacheContext cacheContext = queryContext.CreateCacheContext(); Cache.OeQueryCacheItem queryCacheItem = queryCache.GetQuery(cacheContext); Expression expression; IReadOnlyList <Cache.OeQueryCacheDbParameterValue> parameterValues; IQueryable query = queryContext.EntitySetAdapter.GetEntitySet(dbContext); if (queryCacheItem == null) { var parameterVisitor = new OeConstantToParameterVisitor(); expression = queryContext.CreateExpression(parameterVisitor); expression = new EnumerableToQuerableVisitor().Visit(expression); countExpression = OeQueryContext.CreateCountExpression(expression); queryCache.AddQuery(queryContext.CreateCacheContext(parameterVisitor.ConstantToParameterMapper), expression, countExpression, queryContext.EntryFactory, queryContext.SkipTokenAccessors); parameterValues = parameterVisitor.ParameterValues; } else { expression = (Expression)queryCacheItem.Query; queryContext.EntryFactory = queryCacheItem.EntryFactory; queryContext.SkipTokenAccessors = queryCacheItem.SkipTokenAccessors; countExpression = queryCacheItem.CountExpression; parameterValues = cacheContext.ParameterValues; } expression = new OeParameterToVariableVisitor().Translate(expression, parameterValues); expression = queryContext.TranslateSource(dbContext, expression); if (queryContext.ODataUri.QueryCount.GetValueOrDefault()) { countExpression = (MethodCallExpression)queryContext.TranslateSource(dbContext, countExpression); countExpression = (MethodCallExpression) new OeParameterToVariableVisitor().Translate(countExpression, parameterValues); } else { countExpression = null; } return(expression); }
public OeEf6DataAdapter(Cache.OeQueryCache queryCache, OeEf6OperationAdapter operationAdapter) : base(queryCache, operationAdapter) { }
public OeEf6DataAdapter(Cache.OeQueryCache queryCache) : this(queryCache, new OeEf6OperationAdapter(typeof(T))) { }
public OeEfCoreSqlServerDataAdapter(DbContextOptions <T> options, Cache.OeQueryCache queryCache) : base(options, queryCache, new OeEfCoreSqlServerOperationAdapter(typeof(T))) { }
public OeEfCoreSqlServerDataAdapter(Cache.OeQueryCache queryCache) : this(null, queryCache) { }
public OeDataAdapter(Cache.OeQueryCache queryCache, OeOperationAdapter operationAdapter) { QueryCache = queryCache ?? new Cache.OeQueryCache(true); OperationAdapter = operationAdapter; }
public OeEfCorePostgreSqlDataAdapter(DbContextOptions options, Cache.OeQueryCache queryCache) : base(options, queryCache, new OeEfCorePostgreSqlOperationAdapter(typeof(T))) { base.IsDatabaseNullHighestValue = true; }
private static Expression GetFromCache(OeQueryContext queryContext, T dbContext, Cache.OeQueryCache queryCache, out MethodCallExpression countExpression) { Cache.OeCacheContext cacheContext = queryContext.CreateCacheContext(); Cache.OeQueryCacheItem queryCacheItem = queryCache.GetQuery(cacheContext); Expression expression; IReadOnlyList <Cache.OeQueryCacheDbParameterValue> parameterValues; if (queryCacheItem == null) { var parameterVisitor = new OeConstantToParameterVisitor(); expression = queryContext.CreateExpression(parameterVisitor); expression = new OeEf6EnumerableToQuerableVisitor().Visit(expression); cacheContext = queryContext.CreateCacheContext(parameterVisitor.ConstantToParameterMapper); countExpression = queryContext.CreateCountExpression(expression); queryCache.AddQuery(cacheContext, expression, countExpression, queryContext.EntryFactory); parameterValues = parameterVisitor.ParameterValues; } else { expression = (Expression)queryCacheItem.Query; queryContext.EntryFactory = queryCacheItem.EntryFactory; countExpression = queryCacheItem.CountExpression; parameterValues = cacheContext.ParameterValues; } expression = new OeParameterToVariableVisitor().Translate(expression, parameterValues); expression = queryContext.TranslateSource(dbContext, expression); if (queryContext.IsQueryCount()) { countExpression = (MethodCallExpression)queryContext.TranslateSource(dbContext, countExpression); countExpression = (MethodCallExpression) new OeParameterToVariableVisitor().Translate(countExpression, parameterValues); } else { countExpression = null; } return(expression); }
private static IAsyncEnumerable <TResult> GetFromCache <TResult>(OeQueryContext queryContext, T dbContext, Cache.OeQueryCache queryCache, out MethodCallExpression countExpression) { countExpression = null; Cache.OeCacheContext cacheContext = queryContext.CreateCacheContext(); Cache.OeQueryCacheItem queryCacheItem = queryCache.GetQuery(cacheContext); Func <QueryContext, IAsyncEnumerable <TResult> > queryExecutor; IReadOnlyList <Cache.OeQueryCacheDbParameterValue> parameterValues; IQueryable query = queryContext.EntitySetAdapter.GetEntitySet(dbContext); if (queryCacheItem == null) { var parameterVisitor = new OeConstantToParameterVisitor(); Expression expression = queryContext.CreateExpression(parameterVisitor); expression = queryContext.TranslateSource(dbContext, expression); queryExecutor = dbContext.CreateAsyncQueryExecutor <TResult>(expression); countExpression = OeQueryContext.CreateCountExpression(expression); queryCache.AddQuery(queryContext.CreateCacheContext(parameterVisitor.ConstantToParameterMapper), queryExecutor, countExpression, queryContext.EntryFactory, queryContext.SkipTokenAccessors); parameterValues = parameterVisitor.ParameterValues; } else { queryExecutor = (Func <QueryContext, IAsyncEnumerable <TResult> >)queryCacheItem.Query; queryContext.EntryFactory = queryCacheItem.EntryFactory; queryContext.SkipTokenAccessors = queryCacheItem.SkipTokenAccessors; countExpression = queryCacheItem.CountExpression; parameterValues = cacheContext.ParameterValues; } var queryContextFactory = dbContext.GetService <IQueryContextFactory>(); QueryContext efQueryContext = queryContextFactory.Create(); foreach (Cache.OeQueryCacheDbParameterValue parameterValue in parameterValues) { efQueryContext.AddParameter(parameterValue.ParameterName, parameterValue.ParameterValue); } if (queryContext.ODataUri.QueryCount.GetValueOrDefault()) { countExpression = (MethodCallExpression)queryContext.TranslateSource(dbContext, countExpression); countExpression = (MethodCallExpression) new OeParameterToVariableVisitor().Translate(countExpression, parameterValues); } else { countExpression = null; } return(queryExecutor(efQueryContext)); }
public OeEfCoreDataAdapter(DbContextOptions options, Cache.OeQueryCache queryCache) : this(options, queryCache, new OeEfCoreOperationAdapter(typeof(T), _entitySetAdapters)) { }
public OeLinq2DbDataAdapter(Cache.OeQueryCache queryCache, Db.OeOperationAdapter operationAdapter) : base(queryCache, operationAdapter) { }
public OeLinq2DbDataAdapter(Cache.OeQueryCache queryCache) : base(queryCache, new OeLinq2DbOperationAdapter(typeof(T))) { }
public EfCorePostgreSqlDataAdapter(DbContextOptions <T> options, Cache.OeQueryCache queryCache) : base(options, queryCache, new EfCorePostgreSqlOperationAdapter(typeof(T))) { }
public OeEf6SqlServerDataAdapter(Cache.OeQueryCache queryCache) : base(queryCache, new OeEf6SqlServerOperationAdapter(typeof(T))) { }