Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/elixneto/CollectionMapper.RavenDB.NetCore


https://github.com/elixneto/CollectionMapper.RavenDB.NetCore

Last synced: about 2 months ago
JSON representation

Awesome Lists containing this project

README

        

# 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
```csharp
public class MyCustomMapper : RavenDBCollectionMapper
{
public MyCustomMapper()
{
Map("MyUniqueAccounts");
Map("SuperSpecialBanks");
Map("USER");
Map("Fruits", typeof(Apple), typeof(Banana), typeof(Strawberry));
...
...
}
}

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

private static Lazy store = new Lazy(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;
}
}
```