示例#1
0
        /// <summary>Gets or sets the compiled action to update the internal query.</summary>
        /// <value>The compiled action to update the internal query.</value>
        /// <summary>Adds an or get a filter queryable from the context.</summary>
        /// <param name="context">The context to add or get a filter queryable.</param>
        /// <returns>the filter queryable fromt the context.</returns>
        public BaseQueryFilterQueryable AddOrGetFilterQueryable(DbContext context)
        {
            BaseQueryFilterQueryable filterQueryable;
            var set = GetDbSetCompiled.Value(context);

            if (!QueryFilterManager.CacheWeakFilterQueryable.TryGetValue(set, out filterQueryable))
            {
#if EF5 || EF6
                var objectQuery = set.GetObjectQuery(ElementType);
                filterQueryable = CreateFilterQueryableCompiled.Value(context, this, objectQuery);
                QueryFilterManager.CacheWeakFilterQueryable.Add(set, filterQueryable);
#elif EFCORE
                // todo: Create compiled version
                var field         = set.GetType().GetField("_entityQueryable", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
                var internalQuery = field.GetValue(set);

                var valueProperty      = internalQuery.GetType().GetProperty("Value");
                var valueInternalQuery = valueProperty.GetValue(internalQuery);

                filterQueryable = CreateFilterQueryableCompiled.Value(context, this, valueInternalQuery);
                QueryFilterManager.CacheWeakFilterQueryable.Add(set, filterQueryable);
#endif
            }

            return(filterQueryable);
        }
示例#2
0
        /// <summary>Compile the action to update the internal query.</summary>
        /// <param name="context">The context to update the query from.</param>
        /// <param name="query">The query to change the internal query.</param>
        public void UpdateInternalQuery(DbContext context, object query)
        {
            // todo: Convert to expression once EF team fix the cast issue: https://github.com/aspnet/EntityFramework/issues/3736
            var set = GetDbSetCompiled.Value(context);

            var field         = set.GetType().GetField("_entityQueryable", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            var internalQuery = field.GetValue(set);

            var valueProperty = internalQuery.GetType().GetProperty("Value");


            valueProperty.SetValue(internalQuery, query);
        }