Current filter:
                                You should refresh the page.
                                Support Center
                                  • This article describes the correlation between the availability of the New, Delete, Link, Unlink Actions and the way collection properties are declared.

                                1 Solution

                                Creation Date Rating Importance Sort by

                                Business Model Design

                                XAF distinguishes between five collection declaration types:

                                1. XPCollection type collection with the Association attribute applied - by default, the New/Delete/Link/Unlink Actions are active.
                                2. XPCollection type collection with the Association and Aggregated attributes applied- by default, the New/Delete Actions are active, the Link/Unlink Actions are inactive.
                                3. XPCollection type collection without the Association attribute (filtered by Criteria or populated with custom content (LoadingEnabled=false)) - by default, the New/Delete/Link/Unlink Actions are active.
                                4. BindingList type collection containing persistent objects - by default, the New/Delete/Link/Unlink Actions are active.
                                5. BindingList type collection containing non-persistent objects - by default, the New/Delete/Link/Unlink Actions are inactive.

                                You can deactivate the New/Delete/Link/Unlink actions manually via the BindingBehavior, AllowNew and AllowDelete properties.

                                Let's consider each declaration type in greater detail.

                                1. XPCollection with association.

                                [Association("CollectionProperties-AssociatedObject")] public XPCollection<AssociatedObject> Association { get { return GetCollection<AssociatedObject>("Association"); } }

                                This is the most common way in which to define a collection of associated objects. The collection is managed via XAF/XPO internals and supports the New/Delete/Link/Unlink Actions.

                                2. Aggregated XPCollection with association.

                                [Association("CollectionProperties-AggregatedObject"), Aggregated] public XPCollection<AggregatedObject> AggregatedAssociation { get { return GetCollection<AggregatedObject>("AggregatedAssociation"); } }

                                An Aggregated collection with an association means that objects contained in the collection cannot exist without their owner object. So, there is no collection of objects that can serve as the source for the "link" operation. That's why only the New and Delete Actions are available for this collection.

                                3. XPCollection without association.

                                private XPCollection<NoAssociationObject> _NoAssociation; [CollectionOperationSet(AllowAdd = false, AllowRemove = false)] public XPCollection<NoAssociationObject> NoAssociation { get { if(_NoAssociation == null) { _NoAssociation = new XPCollection<NoAssociationObject>(Session); _NoAssociation.BindingBehavior = CollectionBindingBehavior.AllowNone; } return _NoAssociation; } }

                                Because the NoAssociationObject is a persistent class that doesn't participate in a relationship, members of the collection should be collected and managed manually. The current design assumes that collection modification should be carried out in code. For this purpose you can use Criteria or create custom content (set the LoadingEnabled option to false, and manually add items to the collection, like in an ordinary list). In the code snippet above, the NoAssociation property returns an XPCollection containing all the exiting NoAssiciationObjects. To prevent the collection from being modified via the UI, the property is decorated with the CollectionOperationSet attribute with AllowAdd and AllowRemove set to False (in versions prior to 12.2, this effect could be achieved by setting the collection binding behavior to "CollectionBindingBehavior.AllowNone"). That is why the New/Delete/Link/Unlink Actions will not be available.

                                4. BindingList containing persistent objects.

                                private BindingList<NoAssociationObject> _PersistentBindingList [CollectionOperationSet(AllowAdd = false, AllowRemove = false)] public BindingList<NoAssociationObject> PersistentBindingList { get { if(_PersistentBindingList == null) { _PersistentBindingList = new BindingList<NoAssociationObject>(); _PersistentBindingList.AllowNew = true; _PersistentBindingList.AllowRemove = true; foreach(NoAssociationObject obj in NoAssociation) { _PersistentBindingList.Add(obj); } } return _PersistentBindingList; } }

                                This is a variant of the previous scenario. The only difference is in the collection type (BindingList<>). Collection filling and its elements' processing should be performed manually. Default settings are used to set the binding behavior: "BindingList.AllowNew = true" (Note that "AllowNew = true" is the default behavior of object collections which have the default constructor) and "BindingList.AllowRemove = true". That's why the New/Delete/Link/Unlink Actions will be available in the user interface. However, custom code is needed for proper execution of the New/Delete/Link/Unlink Actions.

                                5. BindingList containing non-persistent objects.

                                private BindingList<SomeObject> nonPersistentObjectBindingList; private void EnsureNonPersistentObjectBindingList() { nonPersistentObjectBindingList = new BindingList<SomeObject>(); //fill nonPersistentObjectBindingList with SomeObject instances... } public BindingList<SomeObject> NonPersistentBindingList { get { EnsureNonPersistentObjectBindingList(); return nonPersistentObjectBindingList; } }

                                Non-persistent object collections are also supported by XAF's user interface and can be displayed in Detail Views. These collections can only be displayed, and the New/Delete/Link/Unlink Actions are not active by default. It doesn't mean that these Actions are not available at all for the non-persistent object collections. Custom Controller should be responsible for the New/Delete/Link/Unlink operations on certain types of non-persistent objects.

                                It is recommended to use the described ways to define collection properties in XAF applications. XAF supports correct processing of persistent object collections only. Non-persistent collections can only be displayed. Collection binding behavior and the AllowNew/AllowDelete properties can be used to deactivate the New/Delete/Link/Unlink Actions.

                                All these declaration types are demonstrated in the Feature Center demo application ("%PUBLIC%\Documents\DevExpress Demos 14.2\Components\eXpressApp Framework\FeatureCenter\CS\FeatureCenter.Module\PropertyEditors\CollectionPropertiesObject.cs" ).

                                See also:
                                eXpressApp Framework > Concepts > Business Model Design > Data Types Supported by built-in Editors

                                If you need additional product information, write to us at or call us at +1 (818) 844-3383

                                FOLLOW US

                                DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio, along with high-performance HTML JS Mobile Frameworks for developers targeting iOS, Android and Windows Phone. Whether using WPF, ASP.NET, WinForms, HTML5 or Windows 10, DevExpress tools help you build and deliver your best in the shortest time possible.

                                Copyright © 1998-2018 Developer Express Inc.
                                All trademarks or registered trademarks are property of their respective owners