문제

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

도움이 되었습니까?

해결책

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.

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top