Skip to content

Commit a82e501

Browse files
authored
Create ef6-query-db-set-filter-by-enable-disable.md
1 parent 4586835 commit a82e501

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
Permalink: ef6-query-db-set-filter-by-enable-disable
3+
---
4+
5+
# EF+ Query Filter Enable/Disable
6+
7+
Filters are very flexible, you can enable and disable them at any time and only for a specific inheritance or interface if desired.
8+
9+
{% include template-example.html %}
10+
```csharp
11+
12+
// using Z.EntityFramework.Plus; // Don't forget to include this.
13+
var ctx = new EntitiesContext();
14+
15+
// CREATE filter by interface
16+
ctx.DbSetFilter<IAnimal>(MyEnum.EnumValue, q => q.Where(x => x.IsDomestic))
17+
18+
// DISABLE filter
19+
ctx.DbSetFilter(MyEnum.EnumValue).Disable();
20+
21+
// SELECT * FROM Dog
22+
var dogs = ctx.Dogs.ToList();
23+
24+
// ENABLE filter
25+
ctx.DbSetFilter(MyEnum.EnumValue).Enable();
26+
27+
// SELECT * FROM Dog WHERE IsDomestic = true
28+
var dogs = ctx.Dogs.ToList();
29+
30+
```
31+
[Try it](https://dotnetfiddle.net/girbYB)

0 commit comments

Comments
 (0)