Conventions and Child Entities

19 views
Skip to first unread message

Yogesh Jagota

unread,
Jul 28, 2015, 6:18:06 AM7/28/15
to RavenDB - 2nd generation document database
Say, we have the following objects:
class Bar
{
     
public int B { get; }
     
public int A { get; set; }
     
public int R { get; set; }
}


class Foo
{
     
public int SomeInt { get; }
     
public int SomeOtherInt { get; set; }
     
public Bar Child { get; set; }
}



... and I have set my JsonContractResolver to only select properties with both CanRead and CanWrite:
protected override List<MemberInfo> GetSerializableMembers(Type objectType)
{
 
var members = base.GetSerializableMembers(objectType).Where(
 m
=> m.MemberType == MemberTypes.Property);

 
return members.Where(member => ((PropertyInfo)member).CanRead && ((PropertyInfo)member).CanWrite).ToList();
}


When I save the Foo document, the SomeInt property is not saved as expected. But the B property of the Child is written to the document. 

I tried this with converters also and custom converters are also not used to serialize a child object.

Is this expected behavior? If yes, then can I enforce the conventions to be applied to the child properties of the document? 

Oren Eini (Ayende Rahien)

unread,
Jul 28, 2015, 6:30:07 AM7/28/15
to ravendb
This is a JSON.Net question, not a strictly RavenDB one.

Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Yogesh Jagota

unread,
Jul 28, 2015, 6:53:54 AM7/28/15
to RavenDB - 2nd generation document database, aye...@ayende.com
I have never used Json.Net before RavenDB. I will research the issue as a Json.Net one, not RavenDB. Thanks.

Kijana Woodard

unread,
Jul 28, 2015, 11:53:34 AM7/28/15
to rav...@googlegroups.com
Are you sure you want to change those conventions? Why?

I regularly use "get only" properties in my documents. It is especially useful for making indexing easier as well as forensics and debugging.

On Tue, Jul 28, 2015 at 5:53 AM, Yogesh Jagota <justj...@jagotagroup.com> wrote:
I have never used Json.Net before RavenDB. I will research the issue as a Json.Net one, not RavenDB. Thanks.

--

Yogesh Jagota

unread,
Jul 28, 2015, 3:33:16 PM7/28/15
to RavenDB - 2nd generation document database, kijana....@gmail.com
I know they have their uses, but I haven't found a use for them. Yet. Also, this question was more because of custom converters. I have some types which need to be serialized to the database (for example a month/year type). The type gets serialized properly on the main document but is saved as a list (because it implements a IEnumerable) in the sub/child object. Sadly I couldn't find a solution to the issue.
Reply all
Reply to author
Forward
0 new messages