sasjaq
sasjaq

Reputation: 771

RavenDB - where condition on included object

Lets have theese objects:

public class Obj1
{
    public string Id { get; set; }
}

public class Obj2
{
    public string Id { get; set; }
    public string Obj1Id { get; set; }
}

public class Obj3
{
    public string Id { get; set; }
    public string Obj2Id { get; set; }
}

I use include like this:

var objs3 = session.Query<Obj3>()
    .Customize(x => x.Include<Obj3>(o3 => o3.Obj2Id))
    .Take(1000)
    .ToList();
foreach (var obj3 in objs3)
{
    var obj2 = session.Load<Obj2>(obj3.Obj2Id);
    //do something with it
}

My question is, is there possibility to add to query something like .Where(o2 => o2.Obj1Id == "some/Id")? Query knows nothing about Obj2 on the client (Linq) side, but server side works with them, because this makes only one request to the DB.

I try to look how to works indexes and projections, but no luck with some constructions. Maybe my view is deformed from relational databases and there are other solutions, that need my structures to be redefined...

My other solution is to add Obj1Id to Obj3, but that will makes duplicites (I can live with this ;) )

Some extra info to objects:
- Obj1 is unique for each customer, so there is about 200 documents
- Obj2 : Obj3 is 1 : 1 siblings, each with own point of view properties, both about 100.000 for each customer

Bonus question: Is there something like Inclide chaining? Including Obj1 inside of Including Obj2? (this I won't use, is just question)

Upvotes: 2

Views: 268

Answers (2)

Daniel Lang
Daniel Lang

Reputation: 6839

As Oren said, you have condition within the include. So you can either restructure your data, or use a multi map (and maybe also reduce) index if both Obj2 and Obj3 have something in common, like the Id of Obj1.

Which way is better in your case really depends on the kind of data you have, no general answer here. (Maybe you can post another, more concrete question with actual class-names instead of abstract names like Obj1-3).

Upvotes: 0

Ayende Rahien
Ayende Rahien

Reputation: 22956

No, you can't add condition to the include. It is either all the way in, or not at all.

Upvotes: 1

Related Questions