Skip to content

Commit 4586835

Browse files
authored
Create ef6-query-db-set-filter-by-inheritance-interface.md
1 parent 223816e commit 4586835

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
Permalink: ef6-query-db-set-filter-by-inheritance-interface
3+
---
4+
5+
# EF+ Query Filter By Inheritance/Interface
6+
7+
Filter can be enabled and disabled by class inheritance and interface.
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 inheritance
16+
ctx.DbSetFilter<BaseDog>(q => q.Where(x => !x.IsDangerous));
17+
18+
// CREATE filter by interface
19+
ctx.DbSetFilter<IAnimal>(q => q.Where(x => x.IsDomestic));
20+
21+
// SELECT * FROM Cat WHERE IsDomestic = 1
22+
var cats = ctx.Cats.ToList();
23+
24+
// SELECT * FROM Dog WHERE IsDomestic = 1 AND IsDangerous = 0
25+
var dogs = ctx.Dogs.ToList();
26+
27+
```
28+
[Try it](https://dotnetfiddle.net/flFnBf)

0 commit comments

Comments
 (0)