Includes across multiple types

131 views
Skip to first unread message

Chris Marisic

unread,
May 2, 2012, 3:03:58 PM5/2/12
to rav...@googlegroups.com
Suppose I have documents

thing { name:blah, owner: persons/1, id:things/1 }
thing { name:other, owner: company/1, id:things/2 }

person { name: bob, id:persons/1 }|
company { name:fedex, id:company/1 }|

Is it possible to do something like

session.Load<Thing >("things/1").Include<Person>(x=>x.Owner).Include<Company>(x=>x.Owner)

Itamar Syn-Hershko

unread,
May 2, 2012, 3:09:50 PM5/2/12
to rav...@googlegroups.com
No need

session.Load<Thing>(id).Include(x => x.Owner)

Will do

The server will look at the requested fields and pull the json docs from store - it doesn't care about the type

Oren Eini (Ayende Rahien)

unread,
May 2, 2012, 3:15:52 PM5/2/12
to rav...@googlegroups.com
It sounds like you are trying to dO multi level include, is this what you are doIng?

Chris Marisic

unread,
May 2, 2012, 3:24:51 PM5/2/12
to rav...@googlegroups.com
No I don't want to do a multiple level include, I'm exploring allowing 1 type of document (Thing) to have multiple types of owners and from what Itamar said it should. Actually typing out code this should be the real usage correct?

Session.Include<Thing>(x => x.Owner).Load<Thing>("things/1");

This almost seems wrong as I really want to get back a company or a person depending on Owner, but I see it's setup like this so i can properly use strongly typed access to reach x=>x.Owner of Thing, correct? That using less strong typing that it would be the same as: Session.Include("Owner").Load<Thing>("things/1"); correct?

Itamar Syn-Hershko

unread,
May 2, 2012, 6:12:06 PM5/2/12
to rav...@googlegroups.com
Too many questions :)

The syntax is actually

Session.Include<Thing>(x => x.Owner).Load("things/1"); 

And what it does is pull the JSON documents "things/1" and all other documents that are mentioned in it's x.Owner property. It doesn't care about the type. The client API will do the conversion for you when you deserialize (e.g. call Load and use that ID)
Reply all
Reply to author
Forward
0 new messages