如何在共享托管环境中运行RavenDB?

时间:2010-08-09 21:23:08

标签: c# asp.net-mvc-2 shared-hosting ravendb

RavenDB能够以“嵌入式”模式运行,据我所知,该模式应该允许它在共享托管环境中运行。

有没有人知道它如何在ASP.NET MVC应用程序中运行,以及执行此操作的最佳做​​法是什么?

托管环境中是否存在我需要注意的依赖项?

1 个答案:

答案 0 :(得分:13)

我使用ASP.NET MVC 3和RavenDB 1.0.0.371在共享托管环境http://www.winhost.com/中运行RavenDB,该版本于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管理工作室。

相关问题