Skip to content

Register configurations from document type class #983

@bradyclifford

Description

@bradyclifford

Add ability to register indexes, foreign keys, grants, other document mapping needs, etc. for a document type from within the document type class using a static method called ConfigurePersistence(MartenRegistry).

If FubuMVC.Marten sees that in a document type, call it before creating the DocumentStore.

public class DocumentTypeExample
{

   public Guid Id { get; set; }
   public string FirstName { get; set; }
   public int AssigneeId { get; set; }
   public int Number { get; set; }

   public static void ConfigurePersistence(MartenRegistry registry) 
   {
        registry.MappingFor(this).DatabaseSchemaName = "other";        
        registry.For(this).ForeignKey<User>(x => x.AssigneeId);
        registry.For(this).GinIndexJsonData();

        registry.For<User>().Duplicate(x => x.FirstName, configure:idx =>
        {
            idx.IndexName = "idx_special";
            idx.Method = IndexMethod.hash;
        });

        registry.For(this).Index(x => x.Number, x =>
        {
            x.Method = IndexMethod.brin;
            x.Casing = ComputedIndex.Casings.Lower;
            x.IndexName = "mt_my_name";
            x.IsConcurrent = true;
            x.IsUnique = true;
            x.Where = "(data ->> 'Number')::int > 10";
        });

   }

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions