Support for adding Discriminators to a collection Automatically

XMLWordPrintableJSON

    • Type: New Feature
    • Resolution: Done
    • Priority: Major - P3
    • 2.1
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Currently, when using a hierarchy of types (Animal -> Cat, Dog), it is required to always use the base class as the generic type on collection (Animal).

      That's fine, but if I only want to then work with Cats, I must add the discriminator in manually to every filter. There should be a way to do this automatically.

      ------------------------
      There is currently a commit here (https://github.com/craiggwilson/mongo-csharp-driver/tree/oftype) that adds a method called OfType to IMongoCollection<T> which does this exact thing. It includes the discriminator with every filter.

      For instance, `db.GetCollection<Animal>("animals").OfType<Cat>();` returns an IFilteredMongoCollection<Cat>, which implements IMongoCollection<Cat>. From here, everything that can be done on a normal collection can be done on this collection, except the discriminator will be added to all filters.

            Assignee:
            Craig Wilson
            Reporter:
            Craig Wilson
            Votes:
            4 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: