【问题标题】:RavenDB Embedded Versioning not workingRavenDB 嵌入式版本控制不起作用
【发布时间】:2014-05-03 13:12:09
【问题描述】:

我正在尝试在嵌入的 RavenDB 中使用版本控制包,但我似乎无法查询修订。

我正在使用 Global.asax.cs 中的代码初始化数据库

// Initialise RavenDB embedded
Store = new EmbeddableDocumentStore
{
    DataDirectory = "~/App_Data",
    UseEmbeddedHttpServer = true,
};

Store.ActivateBundle("Versioning");
Store.Initialize();

ActivateBundle方法是一个扩展方法:(来自this question

    public static void ActivateBundle(this EmbeddableDocumentStore documentStore, string bundleName)
{
    var settings = documentStore.Configuration.Settings;
    var activeBundles = settings[Constants.ActiveBundles];
    if (string.IsNullOrEmpty(activeBundles))
        settings[Constants.ActiveBundles] = bundleName;
    else if (!activeBundles.Split(';').Contains(bundleName, StringComparer.OrdinalIgnoreCase))
        settings[Constants.ActiveBundles] = activeBundles + ";" + bundleName;
}

我正在使用此代码查询修订:

        public IList<FormRevision> GetRevisions(Guid formId)
    {
        using (var session = MvcApplication.Store.OpenSession())
        {
            var revisions = session.Advanced.GetRevisionsFor<Form>(formId.ToString(), 0, 10);

            return revisions.Select(formRevision => session.Advanced.GetMetadataFor(formRevision)).Select(metadata => new FormRevision
            {
                FormId = formId, 
                RevisionNumber = metadata.Value<int>("Raven-Document-Revision"), 
                RevisionDateTime = metadata.Value<DateTime>("Last-Modified")
            }).ToList();
        }
    }

GetRevisionsFor 方法没有返回任何数据。

【问题讨论】:

    标签: .net ravendb


    【解决方案1】:

    根据documentation

    默认情况下,版本控制包将跟踪所有文档的历史记录,并且从不清除旧版本。

    原来对于嵌入式数据库,必须添加版本控制配置文档。

            using (var session = Store.OpenSession())
            {
                session.Store(new
                {
                    Exclude = false,
                    Id = "Raven/Versioning/DefaultConfiguration"
                });
                session.SaveChanges();
            }
    

    这段代码在linked question,但是我在阅读了在线文档中的默认配置后最初没有添加它。事实证明,必须添加此文档才能进行版本控制。

    【讨论】:

      猜你喜欢
      • 2019-02-01
      • 2018-03-10
      • 1970-01-01
      • 1970-01-01
      • 2016-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多