Esempio n. 1
1
        // private static methods
        private static Boolean CanBeEvaluatedLocally(Expression expression, IQueryProvider queryProvider)
        {
            // any operation on a query can't be done locally
            var constantExpression = expression as ConstantExpression;
            if (constantExpression != null)
            {
                var query = constantExpression.Value as IQueryable;
                if (query != null && (queryProvider == null || query.Provider == queryProvider))
                {
                    return false;
                }
            }

            var methodCallExpression = expression as MethodCallExpression;
            if (methodCallExpression != null)
            {
                Type declaringType = methodCallExpression.Method.DeclaringType;
                if (declaringType == typeof (Enumerable) || declaringType == typeof (Queryable))
                {
                    return false;
                }
            }

            if (expression.NodeType == ExpressionType.Convert && expression.Type == typeof (Object))
            {
                return true;
            }

            if (expression.NodeType == ExpressionType.Parameter || expression.NodeType == ExpressionType.Lambda)
            {
                return false;
            }

            return true;
        }
Esempio n. 2
0
    public void SetUp()
    {
      _mockRepository = new MockRepository();
      _providerMock = _mockRepository.StrictMock<IQueryProvider> ();

      _intArrayExpression = ExpressionHelper.CreateNewIntArrayExpression ();
    }
        internal static bool IsEntityFramework(IQueryProvider provider) {
            var type = provider.GetType().FullName;

            return type == "System.Data.Entity.Internal.Linq.DbQueryProvider"
                || type == "Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider"
                || type == "Microsoft.Data.Entity.Query.Internal.EntityQueryProvider";
        }
 public ContentQueryTranslator( IQueryProvider provider, ITableFinder tableFinder )
 {
    this.provider = provider;
    this.tableFinder = tableFinder;
    Skip = -1;
    Take = -1;
 }
        public ExpressionBuilderParameters(ParameterExpression[] parameters, IQueryProvider queryProvider, Type elementType, IXmlNamespaceResolver namespaceResolver, bool mayRootPathBeImplied, IOperatorImplementationProvider operatorImplementationProvider, Func<Type, IXmlNamespaceResolver, XPathTypeNavigator> navigatorCreator=null)
        {
            Debug.Assert(parameters!=null);
            if (parameters==null)
                throw new ArgumentNullException("parameters");
            Debug.Assert(parameters.Length>0);
            if (parameters.Length==0)
                throw new ArgumentException(
                    string.Format(
                        CultureInfo.CurrentCulture,
                        SR.ArrayShouldHaveElementsException,
                        1,
                        parameters.Length
                    ),
                    "parameters"
                );
            Debug.Assert(queryProvider!=null);
            if (queryProvider==null)
                throw new ArgumentNullException("queryProvider");
            Debug.Assert(elementType!=null);
            if (elementType==null)
                throw new ArgumentNullException("elementType");

            Parameters=new ReadOnlyCollection<ParameterExpression>(parameters);
            ElementType=elementType;
            QueryProvider=queryProvider;
            NamespaceResolver=namespaceResolver;
            MayRootPathBeImplied=mayRootPathBeImplied;
            OperatorImplementationProvider=operatorImplementationProvider;
            NavigatorCreator=navigatorCreator;
        }
        public DefaultEnumeratorProvider(Type entityType, IQueryProvider provider, Expression expression)
        {
            Checker.CheckArgumentNull(entityType, "entityType");
            Checker.CheckArgumentNull(provider, "provider");
            Checker.CheckArgumentNull(expression, "expression");

            EntityType = entityType;
            QueryProvider = provider;
            Expression = expression;
        }
Esempio n. 7
0
        internal TableQuery(IDatabase database, Expression expression)
        {
            if (database == null)
            {
                throw new ArgumentNullException("database");
            }

            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            this.database = database;
            this.expression = expression;
            this.provider = new TableQueryProvider(database);
        }
Esempio n. 8
0
 public TestDbAsyncQueryProvider(IQueryProvider provider)
 {
     _inner = provider;
 }
Esempio n. 9
0
 public SelectAddressStoredProcedure(IQueryProvider provider, PerSchemaSqlDbContext dbContext) : base(provider, dbContext)
 {
 }
Esempio n. 10
0
 internal ProjectionReader(IDataReader reader, Func <ProjectionRow, T> projector, IQueryProvider provider)
 {
     _enumerator = new Enumerator(reader, projector, provider);
 }
Esempio n. 11
0
      public Task<Boolean> RequestPermission()
      {
         var tcs = new TaskCompletionSource<Boolean>();
         if(UIDevice.CurrentDevice.CheckSystemVersion( 6, 0 ))
         {
            var status = ABAddressBook.GetAuthorizationStatus();
            if(status == ABAuthorizationStatus.Denied || status == ABAuthorizationStatus.Restricted)
            {
               tcs.SetResult( false );
            }
            else
            {
               if(addressBook == null)
               {
                  addressBook = new ABAddressBook();
                  provider = new ContactQueryProvider( addressBook );
               }

               if(status == ABAuthorizationStatus.NotDetermined)
               {
                  addressBook.RequestAccess(
                     ( s, e ) =>
                     {
                        tcs.SetResult( s );
                        if(!s)
                        {
                           addressBook.Dispose();
                           addressBook = null;
                           provider = null;
                        }
                     } );
               }
               else
               {
                  tcs.SetResult( true );
               }
            }
         }
         else
         {
            tcs.SetResult( true );
         }

         return tcs.Task;
      }
Esempio n. 12
0
 public QueryBinder(IQueryProvider provider, Expression root)
 {
     _projector = new FieldProjector(CanBeField);
     _provider = provider;
     _root = root;
 }
Esempio n. 13
0
 /// <summary>Constructor.</summary>
 /// <param name="originalProvider">The original provider.</param>
 public QueryIncludeOptimizedProvider(IQueryProvider originalProvider)
 {
     OriginalProvider = originalProvider;
 }
 public ManagedConnectionQuery(IQueryable innerQueryable, IQueryProvider queryProvider)
 {
     _innerQueryable = innerQueryable;
     _queryProvider = queryProvider;
 }
 /** <inheritdoc /> */
 public CacheQueryableBase(IQueryProvider provider) : base(provider)
 {
     // No-op.
 }
 public Query(IQueryProvider provider)
 {
     Provider = provider ?? throw new ArgumentNullException(nameof(provider));
 }
 public QueryProvider(IQueryProvider provider) => _provider = provider;
 public AsyncAdaptedQueryProvider(IQueryProvider queryProvider)
 {
     _queryProvider = queryProvider;
 }
 internal static RemoveReactionPayload Create(IQueryProvider provider, Expression expression)
 {
     return(new RemoveReactionPayload(provider, expression));
 }
 public RemoveReactionPayload(IQueryProvider provider, Expression expression) : base(provider, expression)
 {
 }
 public IEnumeratorProvider CreateEnumeratorProvider(Type entityType, IQueryProvider provider, Expression expression)
 {
     return new LinqEnumeratorProvider(entityType, provider, expression);
 }
 public AsyncDecompiledQueryable(IQueryProvider provider, IQueryable inner) : base(provider, inner)
 {
     this.inner = inner;
 }
 /** <inheritdoc /> */
 public CacheQueryableBase(IQueryProvider provider, Expression expression) : base(provider, expression)
 {
     // No-op.
 }
Esempio n. 24
0
 internal CqlUpdate(Expression expression, IQueryProvider table)
     : base(expression, table)
 {
 }
 public TestAsyncQueryProvider(IQueryProvider provider)
 {
     _provider = provider;
 }
Esempio n. 26
0
 public ExpandableQueryProvider(IQueryProvider provider)
 {
     _provider = provider ?? throw new ArgumentNullException(nameof(provider));
 }
 /// <summary>Constructor.</summary>
 /// <param name="originalProvider">The original provider.</param>
 public QueryIncludeFilterProvider(IQueryProvider originalProvider)
 {
     OriginalProvider = originalProvider;
 }
Esempio n. 28
0
 /// <summary>
 /// Performs evaluation and replacement of independent sub-trees.
 /// </summary>
 /// <param name="expression">The root of the expression tree.</param>
 /// <param name="queryProvider">The query provider.</param>
 /// <returns>A new tree with sub-trees evaluated and replaced.</returns>
 internal static Expression Evaluate(Expression expression, IQueryProvider queryProvider)
 {
     return new SubtreeEvaluator(
         Nominator.Nominate(e => CanBeEvaluatedLocally(e, queryProvider), expression))
         .Evaluate(expression);
 }
 public PullRequestReviewConnection(IQueryProvider provider, Expression expression) : base(provider, expression)
 {
 }
Esempio n. 30
0
 internal static StubIClosable Create(IQueryProvider provider, Expression expression)
 {
     return(new StubIClosable(provider, expression));
 }
 internal static PullRequestReviewConnection Create(IQueryProvider provider, Expression expression)
 {
     return(new PullRequestReviewConnection(provider, expression));
 }
Esempio n. 32
0
 internal Enumerator(IDataReader reader, Func <ProjectionRow, T> projector, IQueryProvider provider)
 {
     _reader    = reader;
     _projector = projector;
     _provider  = provider;
 }
Esempio n. 33
0
 private InterceptingProvider(Func <Expression, Expression> afterUnderlyingVisitor, IQueryProvider underlyingQueryProvider, params Func <Expression, Expression>[] visitors)
 {
     this._underlyingProvider     = underlyingQueryProvider;
     this._afterUnderlyingVisitor = afterUnderlyingVisitor;
     this._visitors = visitors;
 }
Esempio n. 34
0
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="provider"></param>
 public Query(IQueryProvider provider)
     : this(provider, null)
 {
 }
        /// <summary>
        /// Replaces the provider of the expression with the given one.
        /// </summary>
        /// <typeparam name="TEntity">The type of the entity.</typeparam>
        /// <param name="query">The query.</param>
        /// <param name="set">The set.</param>
        /// <param name="provider">The provider of the set.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">
        /// query
        /// or
        /// set
        /// or
        /// provider
        /// </exception>
        /// <exception cref="ArgumentException">The supplied query does not originate from a QueryRootExpression and therefor does not come from Entity Framework. - query</exception>
        public static Expression ReplaceProvider <TEntity>(Expression query, DbSet <TEntity> set, IQueryProvider provider)
            where TEntity : class
        {
            if (query is null)
            {
                throw new ArgumentNullException(nameof(query));
            }
            if (set is null)
            {
                throw new ArgumentNullException(nameof(set));
            }
            if (provider is null)
            {
                throw new ArgumentNullException(nameof(provider));
            }

            var setQuery = provider is IAsyncQueryProvider asyncProvider ?
                           new QueryRootExpression(asyncProvider, set.EntityType) :
                           new QueryRootExpression(set.EntityType);

            var visitor  = new QueryRootExpressionReplaceVisitor(setQuery);
            var replaced = visitor.Visit(query);

            if (!visitor.queryWasReplaced)
            {
                throw new ArgumentException($"The supplied query does not originate from a {nameof(QueryRootExpression)} and therefor does not come from Entity Framework.", nameof(query));
            }

            return(replaced ?? throw new ArgumentException($"The supplied query resulted in a replaces expression which was null. This should not happen.", nameof(query)));
        }
Esempio n. 36
0
 public FakeDbAsyncQueryProvider(IQueryProvider inner)
 {
     _inner = inner;
 }
Esempio n. 37
0
 internal static bool IsLinqToObjectsProvider(IQueryProvider provider)
 {
     return(provider.GetType().FullName.Contains("EnumerableQuery"));
 }
        /// <summary>
        /// Gets the next-page token from the $skiptoken query option in the request URI.
        /// </summary>
        /// <param name="query">Query for which the continuation token is being provided.</param>
        /// <param name="resourceType">Resource type of the result on which the $skip token is to be applied.</param>
        /// <param name="continuationToken">Continuation token parsed into primitive type values.</param>
        public virtual void SetContinuationToken(IQueryable query, ResourceType resourceType, object[] continuationToken)
        {
            if (IsTopRequest())
                return;

            var instanceType = resourceType.InstanceType;
            var queryType = typeof(ODataQuery<>).MakeGenericType(instanceType);
            this.expression = query.Expression;
            this.queryProvider = query.Provider;

            if (queryType.IsAssignableFrom(query.GetType()))
            {
                if (this.SupportsType(instanceType))
                {
                    if (continuationToken != null && continuationToken[0] != null)
                    {
                        var token = Encoding.Default.GetString(Convert.FromBase64String(continuationToken[0].ToString()));
                        var tokenParts = token.Split(':');
                        this.entityTypeName = tokenParts[0];
                        this.lastReceivedPage = Convert.ToInt32(tokenParts[1]);
                    }
                    else
                    {
                        this.entityTypeName = instanceType.Name;
                        this.lastReceivedPage = 1;
                    }

                    var provider = queryType.GetProperty("Provider").GetValue(query, null);
                    var skip = (this.lastReceivedPage * this.PageSizeFor(instanceType)) - this.PageSizeFor(instanceType);
                    var nextContinuationToken = string.Format(CultureInfo.InvariantCulture, "{0}:{1}", skip + this.CurrentOffset(), this.PageSizeFor(instanceType));
                    provider.GetType().GetProperty("ContinuationToken").SetValue(provider, nextContinuationToken, null);
                    provider.GetType().GetProperty("SkipTakeBasedPaging").SetValue(provider, true, null);
                }
            }
        }
 protected internal DecompiledQueryable(IQueryProvider provider, IQueryable inner)
 {
     this.inner = inner;
     this.provider = provider;
 }
Esempio n. 40
0
 public void Setup()
 {
     _provider = MockRepository.GenerateStub<IQueryProvider>();
 }
 /// <summary>
 /// Creates source for initial expression, i.e. From
 /// </summary>
 /// <param name="provider"></param>
 internal QueryableWorkItemStore(WorkItemQueryProvider provider)
 {
     this.provider = provider;
     this.expression = Expression.Constant(this);
 }
Esempio n. 42
0
 // internal static methods
 internal static Expression Bind(IQueryProvider provider, Expression node)
 {
     return new QueryBinder(node).Visit(node);
 }
Esempio n. 43
0
 public RetryQueryable(IQueryProvider queryProvider, IQueryable queryable, IRetryPolicy retryPolicy)
 {
     _queryable = queryable;
     _queryProvider = queryProvider;
     _retryPolicy = retryPolicy;
 }
Esempio n. 44
0
        internal TableQuery(IDatabase database)
        {
            if (database == null)
            {
                throw new ArgumentNullException("database");
            }

            this.database = database;
            this.expression = Expression.Constant(this);
            this.provider = new TableQueryProvider(database);
        }
Esempio n. 45
0
 internal RealmResults(Realm realm, RealmObjectBase.Metadata metadata, RealmResultsProvider realmResultsProvider, Expression expression) : base(realm, metadata)
 {
     Provider   = realmResultsProvider;
     Expression = expression ?? Expression.Constant(this);
 }
 /// <summary>
 /// Performs evaluation and replacement of independent sub-trees.
 /// </summary>
 /// <param name="expression">The root of the expression tree.</param>
 /// <param name="queryProvider">The query provider when the expression is a LINQ query (can be null).</param>
 /// <returns>A new tree with sub-trees evaluated and replaced.</returns>
 public static Expression Evaluate(Expression expression, IQueryProvider queryProvider)
 {
     return new SubtreeEvaluator(new Nominator(e => CanBeEvaluatedLocally(e, queryProvider)).Nominate(expression)).Evaluate(expression);
 }
Esempio n. 47
0
 public IDataReader ExecuteDataReader(IQueryProvider query, CommandBehavior behavior)
 {
     return InternalDatabaseProvider.ExecuteDataReader(query, behavior);
 }
 /// <summary>
 /// Creates sources for consequitive expressions .Where, .OrderBy, etc.
 /// </summary>
 /// <param name="provider"></param>
 /// <param name="expression"></param>
 internal QueryableWorkItemStore(WorkItemQueryProvider provider, Expression expression)
 {
     this.provider = provider;
     this.expression = expression;
 }
Esempio n. 49
0
 // This constructor is called indirectly by LINQ's query methods, just pass to base.
 public NhQueryable(IQueryProvider provider, Expression expression)
     : base(provider, expression)
 {
 }
 public AdsiDirectory(IQueryProvider queryProvider)
     : base(queryProvider)
 {
 }
 internal MyAsyncQueryProvider(IQueryProvider inner)
 {
     _inner = inner;
 }
Esempio n. 52
0
 public IDataReader ExecuteDataReader(IQueryProvider query)
 {
     return InternalDatabaseProvider.ExecuteDataReader(query);
 }
Esempio n. 53
0
 internal TestDbAsyncQueryProvider(IQueryProvider inner)
 {
     _inner = inner;
 }
Esempio n. 54
0
 public int ExecuteNonQuery(IQueryProvider query)
 {
     return InternalDatabaseProvider.ExecuteNonQuery(query);
 }
Esempio n. 55
0
 internal TestAsyncQueryProvider(IQueryProvider inner)
 => _inner = inner;
Esempio n. 56
0
 internal CqlCommand(Expression expression, IQueryProvider table)
 {
     _expression = expression;
     _table = table;
 }
Esempio n. 57
0
 public NhFetchRequest(IQueryProvider provider, Expression expression)
     : base(provider, expression)
 {
 }
Esempio n. 58
0
 public StubIClosable(IQueryProvider provider, Expression expression) : base(provider, expression)
 {
 }
Esempio n. 59
0
      private void CheckStatus()
      {
         if(UIDevice.CurrentDevice.CheckSystemVersion( 6, 0 ))
         {
            var status = ABAddressBook.GetAuthorizationStatus();
            if(status != ABAuthorizationStatus.Authorized)
            {
               throw new SecurityException( "AddressBook has not been granted permission" );
            }
         }

         if(addressBook == null)
         {
            addressBook = new ABAddressBook();
            provider = new ContactQueryProvider( addressBook );
         }
      }