What is the best way of using URLs as keys in RavenDB?
Unfortunately, the semantics of updating an item are not clear in the docs: if the key ends in backslash, it is always an insert, otherwise it could be an update if the key already exists.
But URLs can end up in slash, while RavenDB uses terminating slashes for key generation
RavenDB also supports the notion of Identity, for example if you need IDs to be consecutive. By creating a string Id property in your entity, and setting it to a value ending with a slash (/), you can tell RavenDB to use that as a key prefix for your entity. That prefix followed by the next available integer ID for it will be your entity's ID after you call SaveChanges(). and that forward slash cannot be reconfigured. So it does not really "support" it, but enforce it.
Edit: The same RavenDB documentation page states the following, which does not correspond to the observed behaviour:
You are able to assign to a document any ID as you can imagine. Everything is going to work correctly however you have to be aware that some kind of IDs might cause performance issues when number of documents with custom generated IDs is very high (millions of documents).
The options are: 1. Modify your urls to remove ending slash 2. Url encode the urls (as suggested by RavenDB maintainers) 3. Modify the schema and use database-generated IDs
Option 1 should be safe in most cases. Option 2 would make the keys unreadable, plus I have not managed to make it work (might be a bug in either RavenDB or my code). Option 3 seems to unnecessarily complicate the schema.
What would be the best course of action, in general?