Fork me on GitHub

Working with Marten's Metadata Columns Edit on GitHub


When Marten generates a table for document storage it now adds several metadata columns that further describe the document:

  1. mt_last_modified - a timestamp of the last time the document was modified
  2. mt_dotnet_type - The FullName property of the actual .Net type persisted. This is strictly for information and is not used by Marten itself.
  3. mt_version - A sequential Guid designating the revision of the document. Marten uses this column in its optimistic concurrency checks
  4. mt_doc_type - document name (document hierarchies only)
  5. mt_deleted - a boolean flag representing deleted state (soft deletes only)
  6. mt_deleted_at - a timestamp of the time the document was deleted (soft deletes only)

Finding the Metadata for a Document

You can find the metadata values for a given document object with the following mechanism on IDocumentStore.Advanced:


[Fact]
public void hit_returns_values()
{
    var shop = new CoffeeShop();

    using (var session = theStore.OpenSession())
    {
        session.Store(shop);
        session.SaveChanges();
    }

    var metadata = theStore.Tenancy.Default.MetadataFor(shop);

    metadata.ShouldNotBeNull();
    metadata.CurrentVersion.ShouldNotBe(Guid.Empty);
    metadata.LastModified.ShouldNotBe(default(DateTime));
    metadata.DotNetType.ShouldBe(typeof(CoffeeShop).FullName);
    metadata.DocumentType.ShouldBeNull();
    metadata.Deleted.ShouldBeFalse();
    metadata.DeletedAt.ShouldBeNull();
}