JsonDocument to typed model

98 views
Skip to first unread message

Chris Marisic

unread,
Jun 21, 2012, 8:00:42 PM6/21/12
to rav...@googlegroups.com
If I use the low level APIs to work with RavenDB that return JsonDocuments how am I supposed to get them converted to my domain models equivalently to session.Load<Model>(Key).

I tried to figure it out from the source code, and I see inside Get, it calls down to sessionOperations.TrackEntity<T>(jsonDocument) however I can't seem to access that in anyway from session or session.Advanced.

I've looked at the methods on RavenJObject and none of them seem to be the correct direction.

Itamar Syn-Hershko

unread,
Jun 21, 2012, 9:17:54 PM6/21/12
to rav...@googlegroups.com
The JsonDocument object you got contains the document as a RavenJObject. Use it with a deserializer to get an object

Something like docStore.Conventions.CreateSerializer().Deserialize(new RavenJTokenReader(ravenJObject), type);

will do it

Oren Eini (Ayende Rahien)

unread,
Jun 22, 2012, 12:47:40 AM6/22/12
to rav...@googlegroups.com
You need to do something like:

((InMemorySesionOpearations)session).TrackEntity

On Fri, Jun 22, 2012 at 3:00 AM, Chris Marisic <ch...@marisic.com> wrote:

Chris Marisic

unread,
Sep 20, 2012, 11:58:32 AM9/20/12
to rav...@googlegroups.com
For future reference for anyone the exact type is InMemoryDocumentSessionOperations
Reply all
Reply to author
Forward
0 new messages