在 RavenDB 中存储对象有哪些对象要求(限制)
我正在研究 RavenDB 在系统中的使用(主要作为持久键值缓存),并且需要知道可以存储的实际数据有哪些限制。
文档指出“唯一的要求是根实体字符串 Id 属性”但是所有示例和我看到的教程仅存储简单的字符串、整数、小数、布尔数据类型。
可以存储这个对象吗?
public class StorableObject {
public string Id {get;set;}
public object ValueObject {get;set;}
}
使用这个(sudo)代码?
// 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();
并像这样返回:
var storedObject = session.Load<StorableObject>("objects/123456789");
var request = (HttpWebRequest) storedObject.ValueObject;
感谢您的反馈,请原谅我人为的示例,这是我可以描述我正在尝试做的事情的最简单方法,而无需深入研究一堆领域知识/模型。
凯尔
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Raven 中的所有对象都存储为 JSON 并使用 Json.NET 进行序列化。因此,只要可以序列化您的类型,它就可以工作。
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 可以用作键/值存储。
但它的价值在于知道您存储了哪种类型以供撤回。 “对象”没有帮助,但仍然有可能。
另请注意,如果该值很大(例如以兆字节为单位),则最好使用附件 API : http://ravendb.net/docs/2.5/client-api/attachments
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