26

RavenDB has the ability to run in 'embedded' mode, which as far as I understand, should allow it to be run in a shared hosting environment.

Does anyone have any idea how it would work in an ASP.NET MVC application, and what the best practice for doing it would be?

Are there any dependencies in the hosting environment that I need to be aware of?

4

1 回答 1

13

是的。

我让 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 管理工作室。

于 2011-12-04T16:45:42.923 回答