Q:

Changing the value of an Id in RavenDB

We have an entity named Organization that we use the UniqueConstraints-bundle on. We have a property named NetName that is a UniqueConstraint and an automaticly generated Id.
Since this is unneccesary we want to use the NetName-property as Id instead. So that we don't need UniqueConstraints to know that it is unique and also get the benefit from being able to use Load when we have the NetName.
We needed to clean up our netname a bit before using it as an Id so we created a new temporary-property called TempUniqueNetName that now holds the value of:
"organizations/"+ CleanupId(this.NetName)

So we are now ready to simply move that value to our Id. But we can't get it to work. Our problem is that with the PatchRequest below we end up with a new property named Id in the database but the acctual Id still has the same value (see screenshot). Is there a better (correct) way to change the value of an Id?
The Entity:
class Organization {
   public string Id { get; set; }

   [UniqueConstraint]
   public string NetName { get; set; }

   public string TempUniqueNetName{ get; set; }
}

We want to do something like this:
_documentStore.DatabaseCommands.UpdateByIndex(typeof(Organizations).Name,
            new IndexQuery(),
            new[]
                    {
                        new PatchRequest()
                            {
                                Type = PatchCommandType.Rename,
                                Name = "TempUniqueNetName",
                                Value = new RavenJValue("Id")
                            }
                    });

A:

I don't think you can change the document key via patching.  It's not actually stored with the document or the metadata - it's copied into the @id metadata on load to give you the illusion that it's there, and the Raven Client copies it again into your own identity property in the document.  But really, it's a separate value in the underlying esent document store.  Raven would have to know specifically how to handle this and fake it for you.
You could manually copy the doc from the old id to the new one and delete the old, but that could be time consuming.
There isn't a great answer for renaming a document key right now.  There really should be a DatabaseCommand for rekeying a single document, and separate PatchCommandType to rekey when patching. Perhaps this will be added to raven in the future.

