-
Notifications
You must be signed in to change notification settings - Fork 0
/
FilterVisitor.cs
28 lines (25 loc) · 989 Bytes
/
FilterVisitor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public class FilterVisitor : DefaultExpressionVisitor
{
private readonly IdkWhatImDoingContext _context;
public int FilterValue { get; set; }
public CategoryVisitor(DbContext contextForFilter)
{
_context = (IdkWhatImDoingContext)contextForFilter;
this.FilterValue = _context.CategoryID;
}
public override DbExpression Visit(DbScanExpression expression)
{
if (this.FilterValue > 0)
{
// Get the current expression
var dbExpression = base.Visit(expression);
var binding = expression.Bind();
return binding.Filter(
binding.VariableType
.Variable(binding.VariableName)
.Property("FilterFieldName")
.Equal(DbExpression.FromInt32(this.FilterValue)));
}
return base.Visit(expression);
}
}