see on GitHub

Conventions: Serialization


If you need to modify JsonSerializer object used by the client when sending entities to the server you can register a customization action:

CustomizeJsonSerializer = serializer => throw new CodeOmitted()


To modify the JsonSerializer object used by the client to deserialize entities loaded from the server, you can register a customization action:

CustomizeJsonDeserializer = serializer => throw new CodeOmitted()


In order to customize the entity deserialization from blittable JSON you can use define DeserializeEntityFromBlittable implementation:

DeserializeEntityFromBlittable = (type, blittable) => throw new CodeOmitted()


The default JsonContractResolver used by RavenDB will serialize all properties and all public fields. You can change it by providing own implementation of IContractResolver interface:

JsonContractResolver = new CustomJsonContractResolver()

public class CustomJsonContractResolver : IContractResolver
    public JsonContract ResolveContract(Type type)
        throw new CodeOmitted();

You can also customize behavior of the default resolver by inheriting from DefaultRavenContractResolver and overriding specific methods.

public class CustomizedRavenJsonContractResolver : DefaultRavenContractResolver
    public CustomizedRavenJsonContractResolver(ISerializationConventions conventions) : base(conventions)

    protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
        throw new CodeOmitted();


Controls whatever properties that were not de-serialized to an object properties will be preserved during saving a document again. If false, those properties will be removed when the document will be saved. Default: true.

PreserveDocumentPropertiesNotFoundOnModel = true


For the bulk insert you can configure custom serialization implementation by providing TrySerializeEntityToJsonStream:

BulkInsert =
    TrySerializeEntityToJsonStream = (entity, metadata, writer) => throw new CodeOmitted(),

Numbers (de)serialization

RavenDB client supports out of the box all common numeric value types: int, long, double, decimal etc.
Note that although the (de)serialization of decimals is fully supported, there are server side limitations to numbers in that range.
Other number types like BigInteger must be treated using custom (de)serialization.

IgnoreByRefMembers and IgnoreUnsafeMembers

By default, if you try to store an entity that has ref or unsafe members, the Client will throw an exception when session.SaveChanges() is called.

If IgnoreByRefMembers is set to true and you try to store an entity that has ref members, those members will simply be ignored. The entity will be uploaded to the server with all non-ref members without throwing an exception. The document structure on the server-side will not contain fields for those ref members.

If IgnoreUnsafeMembers is set to true, all pointer members will be ignored in the same manner.

The default value of both these conventions is false.