azure-cosmos-dotnet-repository: Cannot use GetAsync() to retrieve subclasses of T

Describe the bug Cannot retrieve subclass types.

To Reproduce

Expected behavior Return an instance of the subtype.

Actual behavior Returns NULL.

Environment summary SDK Version: 2.8.0 OS Version: Windows 11

Additional context I get the idea of a repository being meant for one specific type. However, there’s something odd about the logic, I think. If I can save any type to my IRepository<T>, I should also be able to retrieve it again. A workaround for me would be to have two repositories, one for each specific sub type. However, that would break my logic to (for example) get all offerings of a specific date, which would be a mixed list of documents and modules.

To overcome the limitation, I also tried to implement my own IRepository<T> instead of using DefaultRepository<T>, so I could add sub type support. However, as most of the classes are internal, it’s not possible to implement your own repo, unless I’m missing something?

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 35 (3 by maintainers)

Most upvoted comments

This is a proof of concept: https://gist.github.com/Krumelur/a875f8d0dd6af9a27b8b51d5e4dd59d3

By adding [JsonConverter(typeof(OfferingJsonConverter))], the custom converter will be executed. However, I need to add set the Item.Type = string.Empty and must add another OfferingType property to make it work.

Long story short, I think if there were an option to ignore Type:

  • Backwards compatibility would be ensured with older versions of the SDK (no change in bahaviour for default setting)
  • It would allow the usage of custom converters, like the one I made or something more sophisticated like this: https://github.com/manuc66/JsonSubTypes

What do y’all think?

When I first started testing the repository, I added a bunch of items and it was working nicely. Those items were subclasses of a base type. All properties of the subclasses end up in the item’s JSON. To answer your question/concern: writing is not the issue.