Vladyslav Kalashnikov
Vladyslav Kalashnikov

Reputation: 247

How to make a subquery using RQL (Raven Query Language)?

I have this relationship between DB entities:

Entity1
- Name
...

Entity2
- Entity1FK
...

What I want to do is to query in RavenDB Studio using RQL all Entity2 which have Entity1 with according name.

This is a RQL query which is not valid but shows what I want to do:

from Entity2
where Entity1FK in (
    from Entity1
    where Name = "name"
    select Id
)  

I want to get all the IDs of Entity1 which have Name "name" and use these IDs in the same query. So, how to make the subquery in RQL? Was not able to find this in docs :(

Upvotes: 3

Views: 737

Answers (1)

Danielle
Danielle

Reputation: 3839

What you want is the Related Documents concept: Look at:

Create Related Documents
https://demo.ravendb.net/demos/csharp/related-documents/create-related-documents

Load Related Documents
https://demo.ravendb.net/demos/csharp/related-documents/load-related-documents

Query Related Documents
https://demo.ravendb.net/demos/csharp/related-documents/query-related-documents

You can access the data of an included document like this in RQL:

from "Orders" as o
load o.Company as c
select {
    CompanyName: c.Name
}

Upvotes: 2

Related Questions