Reference to the object of the parent objects of value objects in RavenDb

I recently played with RavenDB and something annoyed me.

I have an object object with a series of value objects, for example.

class Foo { IList<Bar> Bars { get; set; } } 

There are several times when I want to pass an object of type Bar to a method / class, but at some point I want to refer to the parent object. In the world of NHibernate, it is very simple if I configure it with a ratio of 1 .. *, for example.

 class Bar { Foo Foo { get; set; } } 

However, RavenDb does not really like it, which leads to the fact that I have to create methods such as:

 void DoSomething(Foo foo, Bar bar) { Console.WriteLine(foo); Console.WriteLine(bar); } 

but not

 void DoSomething(Bar bar) { Console.WriteLine(bar.Foo); Console.WriteLine(bar); } 

Is there any way to achieve this with RavenDb?

I understand that RavenDb (and document databases in general) contribute to different thinking about working with entities, if this is just the case when I spend too long in a relational / normalized world, can someone explain how I should structure my code in another db document?

+6
source share
1 answer

Can you do this:

 class Bar { Foo Foo { get; set; } } 

You just need to make sure that you install:

 documentStore.Conventions.CustomizeJsonSerializer = serializer => serializer.ReferenceLoopHandling = ReferenceLoopHandling.Serialize; 
+8
source

Source: https://habr.com/ru/post/889124/


All Articles