如何在共享托管环境中运行 RavenDB?
-
27-09-2019 - |
题
乌鸦数据库 能够在“嵌入式”模式下运行,据我了解,应该允许它在共享托管环境中运行。
有谁知道它在 ASP.NET MVC 应用程序中如何工作,以及实现它的最佳实践是什么?
我需要注意托管环境中的任何依赖项吗?
解决方案
是的。
我在共享托管环境中运行 RavenDB, http://www.winhost.com/, ,使用 ASP.NET MVC 3 和 RavenDB 1.0.0.371(于 2011 年 7 月左右发布)。
我的代码:
public static class Store
{
private static IDocumentStore store = createStore();
private static EmbeddableDocumentStore createStore()
{
var returnStore = new EmbeddableDocumentStore();
returnStore.DataDirectory = @"./PersistedData";
returnStore.Initialize();
return returnStore;
}
public static xxx Read(string key)
{
using (var session = store.OpenSession())
{
var anEntity = session.Query<xxx>().
Where(item => item.key == key).Single();
return anEntity;
}
}
public static void Write(xxx)
{
using (var session = store.OpenSession())
{
session.Store(xxx);
session.SaveChanges();
}
}
}
到目前为止唯一的缺点是我没有 RavenDB 管理工作室。
不隶属于 StackOverflow