Description:
Is there more information available on how to construct complex queries?
For example when I have 3 entities (A,B,C) with associations: [A] 1---->n [B] m<----1 [C]
How do I efficiently query all [A] entities which have a relation with [C]?
Answer:
Please review the How to Compose Complex Criteria help topic. It describes how to create complex queries.
As for your particular task, you can use the following code:
C# public class Task : XPObject {
[Association("TaskAssignmentsTask", typeof(TaskAssignment))]
public XPCollection TaskAssignments {
get{ return GetCollection("TaskAssignments"); }
}
}
public class TaskAssignment : XPObject {
[Association("TaskAssignmentsTask")]
public Task Task;
[Association("TaskAssignmentsPerson")]
public Person Person;
}
public class Person : XPObject {
[Association("TaskAssignmentsPerson", typeof(TaskAssignment))]
public XPCollection TaskAssignments {
get { return GetCollection("TaskAssignments"); }
}
}
new XPCollection(typeof(Task),
new ContainsOperator("TaskAssignments",
new GroupOperator(
new BinaryOperator("Person", myPerson),
new BinaryOperator(
new OperandProperty("Task"),
new OperandProperty("^.Oid"),
BinaryOperatorType.Equal
)
)
)
)
See also:
What criteria should I use to get objects for a collection property which is empty?
How to set query criteria for a collection which is a collection property of a persistent object
How to filter a collection by an associated objects' properties