RavenDb: How to Get All Documents that have an related document?

62 Views Asked by At

So I've looked at the samples which use LoadDocument, but that requires the Id of the document that you're loading. In my case it's the exact opposite. I need all of the primary documents that have a document related to it, for which I know the relationship in the related document based on the id of the primary document.

How do I write it?

I.e.

Primary = {Id, Name} Secondary = {Id, Name, PrimaryId}

So I want to get all of the Primary for which a Secondary (with other criteria about the secondary) exists.

In linq I'd just use from p in session.Primary where session.Secondary.Any(s => s.PrimaryId && whateverElse) select p) but this doesn't work as it doesn't understand it.

I've tried to construct this as a manual index but I can't figure out how to create the link to the related document since LoadDocument only takes the ID of the related document, which from the primary document I don't have it.

0

There are 0 best solutions below