Skip to main content

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 =
{
// Set conventions HERE, e.g.:
MaxNumberOfRequestsPerSession = 50,
AddIdFieldToDynamicObjects = false
// ...
}
}.Initialize())
{
// * Here you can interact with the RavenDB store:
// open sessions, create or query for documents, perform operations, etc.

// * Conventions CANNOT be set here after calling 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.

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) // Set max cache 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.

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

MaxHttpCacheSize = new Size(0, SizeUnit.Megabytes) // Disable caching

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.

Syntax
// Syntax:
public int MaxNumberOfRequestsPerSession { get; set; }

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.

Syntax
// Syntax:
public bool DisableTopologyUpdates { get; set; }

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.

Syntax
// Syntax:
public bool SaveEnumsAsIntegers { get; set; }

UseCompression

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

Syntax
// Syntax:
public bool UseCompression { get; set; }

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 // ChangesApi | Polling

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:

LanguageDefault conventionExample
C#PascalCaseOrderLines
JavacamelCaseorderLines
JavaScriptcamelCaseorderLines

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
{
// .Net properties will be serialized as camelCase in the JSON document when storing an entity
// and deserialized back to PascalCase
CustomizeJsonSerializer = s => s.ContractResolver = new CamelCasePropertyNamesContractResolver()
},

// In addition, the following convention is required when
// making a query that filters by a field name and when indexing.
PropertyNameConverter = memberInfo => FirstCharToLower(memberInfo.Name)

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"