コード例 #1
0
 public OeEfCoreDataAdapter(DbContextOptions options, Cache.OeQueryCache queryCache, OeEfCoreOperationAdapter operationAdapter)
     : base(queryCache, operationAdapter)
 {
     if (options != null)
     {
         _dbContextPool = new DbContextPool <T>(options);
     }
 }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
 public OeEf6DataAdapter(Cache.OeQueryCache queryCache, OeEf6OperationAdapter operationAdapter)
     : base(queryCache, operationAdapter)
 {
 }
コード例 #5
0
 public OeEf6DataAdapter(Cache.OeQueryCache queryCache) : this(queryCache, new OeEf6OperationAdapter(typeof(T)))
 {
 }
コード例 #6
0
 public OeEfCoreSqlServerDataAdapter(DbContextOptions <T> options, Cache.OeQueryCache queryCache)
     : base(options, queryCache, new OeEfCoreSqlServerOperationAdapter(typeof(T)))
 {
 }
コード例 #7
0
 public OeEfCoreSqlServerDataAdapter(Cache.OeQueryCache queryCache) : this(null, queryCache)
 {
 }
コード例 #8
0
 public OeDataAdapter(Cache.OeQueryCache queryCache, OeOperationAdapter operationAdapter)
 {
     QueryCache       = queryCache ?? new Cache.OeQueryCache(true);
     OperationAdapter = operationAdapter;
 }
コード例 #9
0
 public OeEfCorePostgreSqlDataAdapter(DbContextOptions options, Cache.OeQueryCache queryCache)
     : base(options, queryCache, new OeEfCorePostgreSqlOperationAdapter(typeof(T)))
 {
     base.IsDatabaseNullHighestValue = true;
 }
コード例 #10
0
        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);
        }
コード例 #11
0
        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));
        }
コード例 #12
0
 public OeEfCoreDataAdapter(DbContextOptions options, Cache.OeQueryCache queryCache)
     : this(options, queryCache, new OeEfCoreOperationAdapter(typeof(T), _entitySetAdapters))
 {
 }
コード例 #13
0
 public OeLinq2DbDataAdapter(Cache.OeQueryCache queryCache, Db.OeOperationAdapter operationAdapter)
     : base(queryCache, operationAdapter)
 {
 }
コード例 #14
0
 public OeLinq2DbDataAdapter(Cache.OeQueryCache queryCache)
     : base(queryCache, new OeLinq2DbOperationAdapter(typeof(T)))
 {
 }
コード例 #15
0
 public EfCorePostgreSqlDataAdapter(DbContextOptions <T> options, Cache.OeQueryCache queryCache)
     : base(options, queryCache, new EfCorePostgreSqlOperationAdapter(typeof(T)))
 {
 }
コード例 #16
0
 public OeEf6SqlServerDataAdapter(Cache.OeQueryCache queryCache)
     : base(queryCache, new OeEf6SqlServerOperationAdapter(typeof(T)))
 {
 }