I have a class that I want to use for a document key in RavenDB:
public class DocumentKey
{
public string Namespace { get; set; }
public string Id { get; set; }
}
I've also implemented the ITypeConverter
(not the .NET one, the RavenDB-specific one) interface to convert from the reference type to a string (because in the database, the keys are all really just strings).
Finally, I've added the implementation of ITypeConverter
to the IDocumentStore
implementation through the List<ITypeConverter>
exposed through the Conventions.IdentityProviders
property.
However, the signature on the LoadAsync<T>
overloads on the IAsyncDocumentSession
implementation look like this (removed the signatures which take multiple ids for brevity. Also, the same as Load
on the IDocumentSession
interface):
LoadAsync<T>(string id);
LoadAsync<T>(ValueType id);
I really don't want to use value types for my keys for the following reasons:
- I have an abstraction which doesn't have a constraint on the type of the key. Creating separate structures to mirror this just to have value types are very inconvenient.
- I don't have complete control over the type by being restricted to a value type. The value type has a default constructor which defaults the values in a way that I don't want to have to deal with everywhere else in my code.
How can I use a reference type as a document key in RavenDB?