So lets say I have 3 objects Fruit, Apple and Orange. Fruit is the abstract base class for Apple and Orange. When I use session.Store(myApple), it puts it into the Apples collection. myOrange stores in the Oranges collection. Makes sense.
Can I tell Raven that I want a Fruits collection that could hold Apples or Oranges? Mongodb allows this since it lets me explicitly specify the collection name. The RavenDB collections documentation says:
The expected usage pattern is that collections are used to group documents with similar structure, although that is not required. From the database standpoint, a collection is just a group of documents that share the same entity name.
I'd expect it to be something like: session.Store<Fruit>(myApple), or session.Store("Fruits", myApple)
Any ideas? Thanks.
Awl, You can do it using:
session.Store(apple);
session.Advanced.GetMetadataFor(apple)[Constants.RavenEntityName] = "Fruits";
That is the long way to do so. A much better way would be to add this logic globally, it looks something like this:
store.Conventions.FindTypeTagName =
type => type.IsSubclassOf(typeof(Fruit)) ?
DocumentConvention.DefaultTypeTagName(typeof(Fruit)) :
DocumentConvention.DefaultTypeTagName(type);
That will handle this for everything.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With