Skip to content

Commit ef59532

Browse files
committed
added OfType documentation.
1 parent 95a34cb commit ef59532

File tree

1 file changed

+14
-0
lines changed
  • Docs/reference/content/reference/driver/crud

1 file changed

+14
-0
lines changed

Docs/reference/content/reference/driver/crud/index.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,17 @@ Animal
3636
```
3737

3838
The collection instance must be an [`IMongoCollection<Animal>`]({{< apiref "T_MongoDB_Driver_IMongoCollection_1" >}}).
39+
40+
41+
#### Working with Subclasses
42+
43+
The [`OfType`]({{< apiref "M_MongoDB_Driver_IMongoCollection_1_OfType_1">}}) method applies a discriminating filter to all methods of an [`IMongoCollection<T>`]({{< apiref "T_MongoDB_Driver_IMongoCollection_1" >}}). For example, to work only with `Cats` from the "animals" collection:
44+
45+
```csharp
46+
IMongoCollection<Animal> animals = db.GetCollection<Animal>("animals");
47+
48+
IMongoCollection<Cat> cats = animals.OfType<Cat>();
49+
```
50+
51+
{{% note class="warning" %}}It is imperative that the collection retrieved from the database instance be the root of the hierarchy. `db.GetCollection<Cat>("animals")` will NOT include the discriminator.{{% /note %}}
52+

0 commit comments

Comments
 (0)