RavenDB version 2.0. Other versions:

Immutable entities with Raven DB

Whenever you are trying to use a non-default constructor for your entity, do the following to avoid falling into serialization problems with JSON.Net and raven:

  • add a private constructor ... even if it is empty
  • Ensure every readonly property has a "Private setter" on it ... else it won't get populated
  • Use a custom Json resolver like this one:
    public class PrivatePropertySetterResolver : DefaultContractResolver
    	protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
    		var prop = base.CreateProperty(member, memberSerialization);
    		if (!prop.Writable)
    			var property = member as PropertyInfo;
    			if (property != null)
    				var hasPrivateSetter = property.GetSetMethod(true) != null;
    				prop.Writable = hasPrivateSetter;
    		return prop;
Comments add new comment

The comments section is for user feedback or community content. If you seek assistance or have any questions, please post them at our support forums.

REPLY Posted by jgauffin on

That method do not exist anymore (I'm using Raven.Client.Embedded 1.2.0)

Ayende Rahien
REPLY Posted by Ayende Rahien on

Please use our mailing list for support.