Pergunta

I am researching RavenDB for use in a system (mostly as a persistant key-value cache) and need to know what are the limitations of the actual data that can be stored.

The documentation states "The only requirement is that a root entity string Id property" however all the samples and tutorials I am seeing only store simple string, int, decimal, bool data types.

Is it possible to store this object?

public class StorableObject {
   public string Id {get;set;}
   public object ValueObject {get;set;}
}

Using this (sudo) code?

// I just copy and pasted this from a random blog post -- an example to show a complex object with a lot of hierarchy, methods, properties, etc.
string boundary = Guid.NewGuid().ToString();
HttpWebRequest request = HttpWebRequest.Create("http://twitpic.com/api/uploadAndPost")
    as HttpWebRequest;
request.Method = "POST";
request.ContentType = string.Format("multipart/form-data; boundary={0}", boundary);
request.PreAuthenticate = true;

var objectToStore = new StorableObject { ValueObject = request }; 
session.Store(objectToStore);
session.SaveChanges();

And get it back out like this:

var storedObject = session.Load<StorableObject>("objects/123456789");
var request = (HttpWebRequest) storedObject.ValueObject;

Thanks for your feedback, please excuse my contrived example, it was the easiest way I could describe what I am trying to do without delving into a bunch of domain knowledge/models.

Kyle

Foi útil?

Solução

All objects in Raven are stored as JSON and are serialised using Json.NET. So as long as that can serialise your type it'll work.

Outras dicas

RavenDB can be used as a key/value store.

But its value is knowing what type you've stored to pull back. 'Object' isn't helpful, but still possible.

Also note that if the value is huge - as in megabytes, its best to use the Attachments API : http://ravendb.net/docs/2.5/client-api/attachments

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top