KB Article A863
Visible to All Users

What criteria should I use to get objects for a collection property which is empty?

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

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.