Conventions

Conventions give you the ability to customize the Client API behavior. They are accessible from the DocumentStore object:

using (var store = new DocumentStore()
{
    Conventions =
    {
        // customizations go here
    }
}.Initialize())
{

}

You will find many settings to overwrite, allowing you to adjust the client according to your needs. The conventions apply to many different client behaviors. Some of them are grouped and described in the separate articles of this section.

Information

All customizations need to be set before DocumentStore.Initialize() is called.

MaxHttpCacheSize

If you need to modify the maximum http cache size, you can use the following setting:

MaxHttpCacheSize = new Size(256, SizeUnit.Megabytes)

Default size

The default value of this setting is configured as follows:

  • running on 64 bits:

    • if usable memory is lower than or equal to 3GB: 64MB,
    • if usable memory is greater than 3GB and lower than or equal to 6GB: 128MB,
    • if usable memory is greater than 6GB: 512MB,
  • running on 32 bits: 32MB.

The cache is created per database you use.

Disable caching

To disable the caching globally, you can set the MaxHttpCacheSize value to zero:

MaxHttpCacheSize = new Size(0, SizeUnit.Megabytes)

In this scenario, all the requests will be sent to the server to fetch the data.

MaxNumberOfRequestsPerSession

Gets or sets maximum number of GET requests per session. Default: 30.

MaxNumberOfRequestsPerSession = 10

UseOptimisticConcurrency

Controls whether optimistic concurrency is set to true by default for all future sessions. Default: false.

UseOptimisticConcurrency = true

RequestTimeout

It allows you to define the global request timeout value for all RequestExecutors created per database. Default: null.

RequestTimeout = TimeSpan.FromSeconds(90)

DisableTopologyUpdates

Forces you to disable updates of database topology. Default: false.

DisableTopologyUpdates = false

SaveEnumsAsIntegers

It determines if C# enum types should be saved as integers or strings and instructs the LINQ provider to query enums as integer values. Default: false.

SaveEnumsAsIntegers = true

UseCompression

It determines if the client will send headers to the server indicating that it allows compression to be used. Default: true.

UseCompression = true

OperationStatusFetchMode

Changes the way the operation is fetching the operation status when waiting for completion. By default, the value is set to ChangesApi which underneath is using WebSocket protocol when connection is established with the server. On some older systems e.g. Windows 7, the WebSocket protocol might not be available due to the OS and .NET Framework limitations. For that reason, the value can be changed to Polling to bypass this issue.

OperationStatusFetchMode = OperationStatusFetchMode.ChangesApi

Changing fields/properties naming convention

By default whatever casing convention you use in your entities' fields will be reflected server-side.

If following language-specific field casing conventions RavenDB clients use different field/properties naming conventions:

Language Default convention Example
C# PascalCase OrderLines
Java camelCase orderLines
JavaScript camelCase orderLines

This can be configured to allow inter-language operability e.g. store data PascalCase, but keep fields in the application code camelCase.

Using camelCase in C# client

You have to customize JsonSerializer and PropertyNameConverter.

private string FirstCharToLower(string str) => $"{Char.ToLower(str[0])}{str.Substring(1)}";

Serialization = new NewtonsoftJsonSerializationConventions
{
    CustomizeJsonSerializer = s => s.ContractResolver = new CamelCasePropertyNamesContractResolver()
},
PropertyNameConverter = mi => FirstCharToLower(mi.Name)

Changing the Identity Separator

Changes the default separator for automatically generated document IDs.
Can be any char except | (pipe).
Default: / (forward slash).

This affects these ID generation strategies:

IdentityPartsSeparator = '~'

TopologyCacheLocation

Changes the location of topology cache files. Setting this value will check directory existance and write permissions. By default it is set to the application base directory (AppContext.BaseDirectory).

TopologyCacheLocation = @"C:\RavenDB\TopologyCache"

AddIdFieldToDynamicObjects

Determines whether an Id field is automatically added to dynamic objects. Default: true.

AddIdFieldToDynamicObjects = false

ShouldIgnoreEntityChanges

This function can be configured to disable entity tracking for certain entities. Learn more here

WaitForIndexesAfterSaveChangesTimeout

Sets the default timeout for DocumentSession.Advanced.WaitForIndexesAfterSaveChanges method.

Default: 15 Seconds.

WaitForIndexesAfterSaveChangesTimeout = TimeSpan.FromSeconds(10)

WaitForReplicationAfterSaveChangesTimeout

Sets the default timeout for DocumentSession.Advanced.WaitForReplicationAfterSaveChanges method. Default: 15 Seconds.

WaitForReplicationAfterSaveChangesTimeout = TimeSpan.FromSeconds(10)

WaitForNonStaleResultsTimeout

Sets the default timeout WaitForNonStaleResults methods used when querying. Default: 15 Seconds.

WaitForNonStaleResultsTimeout = TimeSpan.FromSeconds(10)