Description:
I have a many-to-many relation which is implemented in one class:
C#public class HelpTopic : XPObject {
public string Name;
[Association("Parent-Children", typeof(HelpTopic))]
public XPCollection Parents {
get { return GetCollection("Parents"); }
}
[Association("Parent-Children", typeof(HelpTopic))]
public XPCollection Children {
get { return GetCollection("Children"); }
}
}
How can I get only the root HelpTopics?
Answer:
You can use one of the following criteria:
C#XPCollection<HelpTopic> rootTopics = new XPCollection<HelpTopic>(session,
new NotOperator(new ContainsOperator("Parents", null)));
XPCollection<HelpTopic> rootTopics = new XPCollection<HelpTopic>(session,
new NotOperator(new ContainsOperator("Parents",
new NotOperator(new NullOperator("Oid")))));
See also:
How to set query criteria for a collection which is a collection property of a persistent object
How to construct complex queries
How to filter a collection by an associated objects' properties
How to create a criterion, which returns an intersection of two many-to-many sets