Entity Framework 6 expression modification [closed]





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I would like to remove the where clause from the expression of IQueryable. Can I do that, please?
There is an extension method what takes an IQueryable as a parameter. This IQueryable contains where clause. I want to query the total number of rows without filtering.










share|improve this question















closed as unclear what you're asking by Derviş Kayımbaşıoğlu, anothermh, Robert Harvey Jan 3 at 23:22


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

























    0















    I would like to remove the where clause from the expression of IQueryable. Can I do that, please?
    There is an extension method what takes an IQueryable as a parameter. This IQueryable contains where clause. I want to query the total number of rows without filtering.










    share|improve this question















    closed as unclear what you're asking by Derviş Kayımbaşıoğlu, anothermh, Robert Harvey Jan 3 at 23:22


    Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.





















      0












      0








      0








      I would like to remove the where clause from the expression of IQueryable. Can I do that, please?
      There is an extension method what takes an IQueryable as a parameter. This IQueryable contains where clause. I want to query the total number of rows without filtering.










      share|improve this question
















      I would like to remove the where clause from the expression of IQueryable. Can I do that, please?
      There is an extension method what takes an IQueryable as a parameter. This IQueryable contains where clause. I want to query the total number of rows without filtering.







      c# entity-framework-6 expression iqueryable






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 3 at 23:18









      Ivan Stoev

      109k788144




      109k788144










      asked Jan 3 at 21:56









      Sándor HatvaniSándor Hatvani

      141210




      141210




      closed as unclear what you're asking by Derviş Kayımbaşıoğlu, anothermh, Robert Harvey Jan 3 at 23:22


      Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









      closed as unclear what you're asking by Derviş Kayımbaşıoğlu, anothermh, Robert Harvey Jan 3 at 23:22


      Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


























          1 Answer
          1






          active

          oldest

          votes


















          4














          Where clauses inside query expression trees are represented as a calls to the Queryable.Where(source, predicate) extension method.



          Hence you can use custom ExpressionVisitor to locate them and remove by returning the first argument (which is the source) like this:



          public static class QueryableUtils
          {
          public static IQueryable<T> RemoveWhere<T>(this IQueryable<T> source)
          {
          var expression = new WhereRemover().Visit(source.Expression);
          if (expression == source.Expression) return source;
          return source.Provider.CreateQuery<T>(expression);
          }

          class WhereRemover : ExpressionVisitor
          {
          protected override Expression VisitMethodCall(MethodCallExpression node)
          {
          // Queryable.Where(source, predicate)
          if (node.Method.DeclaringType == typeof(Queryable) && node.Method.Name == "Where")
          return base.Visit(node.Arguments[0]); // source
          return base.VisitMethodCall(node);
          }
          }
          }


          Note that this will remove all Queryable.Where calls, so use with care.






          share|improve this answer






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            4














            Where clauses inside query expression trees are represented as a calls to the Queryable.Where(source, predicate) extension method.



            Hence you can use custom ExpressionVisitor to locate them and remove by returning the first argument (which is the source) like this:



            public static class QueryableUtils
            {
            public static IQueryable<T> RemoveWhere<T>(this IQueryable<T> source)
            {
            var expression = new WhereRemover().Visit(source.Expression);
            if (expression == source.Expression) return source;
            return source.Provider.CreateQuery<T>(expression);
            }

            class WhereRemover : ExpressionVisitor
            {
            protected override Expression VisitMethodCall(MethodCallExpression node)
            {
            // Queryable.Where(source, predicate)
            if (node.Method.DeclaringType == typeof(Queryable) && node.Method.Name == "Where")
            return base.Visit(node.Arguments[0]); // source
            return base.VisitMethodCall(node);
            }
            }
            }


            Note that this will remove all Queryable.Where calls, so use with care.






            share|improve this answer




























              4














              Where clauses inside query expression trees are represented as a calls to the Queryable.Where(source, predicate) extension method.



              Hence you can use custom ExpressionVisitor to locate them and remove by returning the first argument (which is the source) like this:



              public static class QueryableUtils
              {
              public static IQueryable<T> RemoveWhere<T>(this IQueryable<T> source)
              {
              var expression = new WhereRemover().Visit(source.Expression);
              if (expression == source.Expression) return source;
              return source.Provider.CreateQuery<T>(expression);
              }

              class WhereRemover : ExpressionVisitor
              {
              protected override Expression VisitMethodCall(MethodCallExpression node)
              {
              // Queryable.Where(source, predicate)
              if (node.Method.DeclaringType == typeof(Queryable) && node.Method.Name == "Where")
              return base.Visit(node.Arguments[0]); // source
              return base.VisitMethodCall(node);
              }
              }
              }


              Note that this will remove all Queryable.Where calls, so use with care.






              share|improve this answer


























                4












                4








                4







                Where clauses inside query expression trees are represented as a calls to the Queryable.Where(source, predicate) extension method.



                Hence you can use custom ExpressionVisitor to locate them and remove by returning the first argument (which is the source) like this:



                public static class QueryableUtils
                {
                public static IQueryable<T> RemoveWhere<T>(this IQueryable<T> source)
                {
                var expression = new WhereRemover().Visit(source.Expression);
                if (expression == source.Expression) return source;
                return source.Provider.CreateQuery<T>(expression);
                }

                class WhereRemover : ExpressionVisitor
                {
                protected override Expression VisitMethodCall(MethodCallExpression node)
                {
                // Queryable.Where(source, predicate)
                if (node.Method.DeclaringType == typeof(Queryable) && node.Method.Name == "Where")
                return base.Visit(node.Arguments[0]); // source
                return base.VisitMethodCall(node);
                }
                }
                }


                Note that this will remove all Queryable.Where calls, so use with care.






                share|improve this answer













                Where clauses inside query expression trees are represented as a calls to the Queryable.Where(source, predicate) extension method.



                Hence you can use custom ExpressionVisitor to locate them and remove by returning the first argument (which is the source) like this:



                public static class QueryableUtils
                {
                public static IQueryable<T> RemoveWhere<T>(this IQueryable<T> source)
                {
                var expression = new WhereRemover().Visit(source.Expression);
                if (expression == source.Expression) return source;
                return source.Provider.CreateQuery<T>(expression);
                }

                class WhereRemover : ExpressionVisitor
                {
                protected override Expression VisitMethodCall(MethodCallExpression node)
                {
                // Queryable.Where(source, predicate)
                if (node.Method.DeclaringType == typeof(Queryable) && node.Method.Name == "Where")
                return base.Visit(node.Arguments[0]); // source
                return base.VisitMethodCall(node);
                }
                }
                }


                Note that this will remove all Queryable.Where calls, so use with care.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 3 at 23:18









                Ivan StoevIvan Stoev

                109k788144




                109k788144

















                    Popular posts from this blog

                    Mossoró

                    Error while reading .h5 file using the rhdf5 package in R

                    Pushsharp Apns notification error: 'InvalidToken'