An easy way to map your entities classes to RavenDB collections for .NET applications
Full Documentation:
https://github.com/elixneto/CollectionMapper.RavenDB.NetCore/wiki
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;
}
}