Pergunta

I'm trying to use the Versioning bundle in RavenDB embedded but I can't seem to query the revisions.

I'm initializing the database with this code in Global.asax.cs

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

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

The ActivateBundle method is an extension method: (from 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;
}

I'm querying for the revisions with this code:

        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();
        }
    }

The GetRevisionsFor method is not returning any data.

Foi útil?

Solução

According to the documentation,

By default, the Versioning bundle will track history for all documents and never purge old revisions.

It turns out that for the embedded database, the versioning configuration document must be added.

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

This code is in the linked question, but I didn't add it originally after reading about the default configuration in the online documentation. As it turns out, this document must be added for versioning to work.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top