Igorek
Igorek

Reputation: 15850

Read-only keys in RavenDb or... interopability between RavenDb and Azure Table Storage

I'm looking to host a number of configuration parameters for customers in RavenDb database, while numereous data points that are generated on a minute-by-minute basis for these parameters in Azure Table storage. I need a basic way to connect between RavenDb and ATS. Obviously, this connection is to be done via keys. My issue is that RavenDb uses forward slashes in all of its Id fields, while ATS pukes when a forward slash is used in either PartitionKey or RowKey.

My question is as follows: Is it possible to have a read-only Id key in my RavenDb entities (no setters). Such key approach would return the value of a Guid-based key pre-pended with "entity/" prefix. This way, I can store the Guid-based ID key in raven entities as well and be able to compare ravenEntity.RootId (guid) to storageEntity.PartitionKey (string based on guid). I'm worried that even if my entities seem to persist to Raven and load back OK.. I may have an issue with some more obscure functionality?

Are there other suggested or perhaps worked out approaches to handle such relationship?

Upvotes: 0

Views: 72

Answers (1)

David Boike
David Boike

Reputation: 18625

So you just need something in your RavenDB model, that does not change once created, that you can use to relate to associated data you store in Azure Table Storage?

Well, assuming your RavenDB's document id will not change (and it can't, becuase then it would be a different document) you could use a deterministic guid using the document id.

public class MyModel
{
    public string Id { get; set; }

    // Other stuff

    [JsonIgnore]      // <--- This really doesn't need to be persisted to RavenDB
    public string AzureLookupKey
    {
        get { return "entity/" + Utils.GetDeterministicGuid(this.Id).ToString("n"); }
    }
}

The GetDeterministicGuid(inputString) method could be implemented however you want, although the SO question How to Create Deterministic Guids has a good example right in the question, with other possibilities in the answer.

Instead of using [JsonIgnore] to prevent RavenDB from serializing the data to the database, you could also make it a method.

Upvotes: 0

Related Questions