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;
}
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
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.
add a comment |
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
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.
add a comment |
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
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
c# entity-framework-6 expression iqueryable
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.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
add a comment |
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.
add a comment |
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.
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.
answered Jan 3 at 23:18
Ivan StoevIvan Stoev
109k788144
109k788144
add a comment |
add a comment |