Skip to content

Latest commit

 

History

History
57 lines (47 loc) · 1.88 KB

File metadata and controls

57 lines (47 loc) · 1.88 KB

CollectionMapper.RavenDB.NetCore

An easy way to map your entities classes to RavenDB collections for .NET applications

Wiki

Full Documentation:
https://github.com/elixneto/CollectionMapper.RavenDB.NetCore/wiki

Easy to use

public class MyCustomMapper : RavenDBCollectionMapper
{
    public MyCustomMapper()
    {
        Map<Account>("MyUniqueAccounts");
        Map<Bank>("SuperSpecialBanks");
        Map<User>("USER");
        Map("Fruits", typeof(Apple), typeof(Banana), typeof(Strawberry));
        ...
        ...
    }
}

public class RavenDBDocumentStoreHolderExample
{
    private readonly MyCustomMapper myCustomMapper = new MyCustomMapper();

    private static Lazy<IDocumentStore> store = new Lazy<IDocumentStore>(CreateStore);
    public static IDocumentStore Store => store.Value;
    private static IDocumentStore CreateStore()
    {
        /* you can ignore private properties of your entities classes */
        myCustomMapper.IncludeNonPublicProperties(false);

        IDocumentStore store = new DocumentStore
        {
                Urls = new[] { "http://your_RavenDB_cluster_node" },
                Database = "your_RavenDB_database_name",
                
                Conventions = {
                    /* Here you set the collection mapper */
                    FindCollectionName = (type) => myCustomMapper.FindCollectionBy(type),

                    /* Here you can use the contract resolver to ignore the private properties */
                    Serialization = new NewtonsoftJsonSerializationConventions
                    {
                        JsonContractResolver  = myCustomMapper.GetPropertiesContract()
                    }
                }

        }.Initialize();

        return store;
    }
}