开发者

What are the object requirements (limitations) for storing an object in RavenDB

开发者 https://www.devze.com 2023-02-03 00:47 出处:网络
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 t开发者_如何学Gohat can be stored.

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 t开发者_如何学Gohat 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

0

精彩评论

暂无评论...
验证码 换一张
取 消