Example E980
Visible to All Users

How to: Display a List of Non-Persistent Objects with an Intermediate Container Class and Its Detail View

This example stores a list of books. When a user clicks the Show Duplicate Books action, a popup dialog displays a list of duplicated books and their copy counts. This list is shown with a detail view.

Note:
This example uses an intermediate container class to display a list non-persistent objects. In this case, the ObjectsGetting method cannot be applied. If your application logic does not require complex operations to create non-persistent objects, use the ObjectsGetting method. Refer to the following help topic for implementation details: How to: Display a Non-Persistent Object's List View from the Navigation.

Blazor application: Non-persistent objects in a dialog popup

Implementation Details

  1. Declare the Book persistent class. Objects of this class denote books in a collection.
  2. Declare two non-persistent classes—Duplicate to store unique book titles and the total number of books with these titles, and DuplicatesList to aggregate the Duplicate objects.
  3. In a controller, implement a method that iterates through persistent Book objects, counts the number of copies of each book, and saves this information in a dictionary.
  4. Implement a method that iterates through dictionary items and creates Duplicate objects for items with a value greater than one (books with more than one copy). Add Duplicate objects to a DuplicatesList collection.
  5. Add the PopupWindowShowAction to display a popup dialog when a user clicks the Show Duplicate Books action. Handle the CustomizePopupWindowParams event and call the CreateDetailView method to create a Detail View for the DuplicatesList object.

See the following help topic for more detailed information: How to: Display a List of Non-Persistent Objects in a Popup Dialog

Files to Review

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

EFCore/NonPersistentListViewEF/NonPersistentListViewEF.Module/BusinessObjects/Book.cs
C#
using DevExpress.Persistent.Base; using DevExpress.Persistent.BaseImpl.EF; namespace NonPersistentListView.Module { [DefaultClassOptions] public class Book : BaseObject { public virtual string Title { get; set; } } }
EFCore/NonPersistentListViewEF/NonPersistentListViewEF.Module/BusinessObjects/Duplicate.cs
C#
using System.ComponentModel; using DevExpress.ExpressApp.DC; using DevExpress.ExpressApp; namespace NonPersistentListView.Module { [DomainComponent] public class Duplicate: NonPersistentLiteObject { public string Title { get; set; } public int Count { get; set; } } [DomainComponent] public class DuplicatesList: NonPersistentLiteObject { private BindingList<Duplicate> duplicates; public DuplicatesList() { duplicates = new BindingList<Duplicate>(); } public BindingList<Duplicate> Duplicates { get { return duplicates; } } } }
EFCore/NonPersistentListViewEF/NonPersistentListViewEF.Module/Controllers/ShowDuplicateBooksController.cs
C#
using DevExpress.ExpressApp; using DevExpress.ExpressApp.Actions; using DevExpress.Persistent.Base; using System.Collections; namespace NonPersistentListView.Module { public class ShowDuplicateBooksController : ObjectViewController<ListView, Book> { public ShowDuplicateBooksController() { PopupWindowShowAction showDuplicatesAction = new PopupWindowShowAction(this, "ShowDuplicateBooks", PredefinedCategory.View); showDuplicatesAction.CustomizePopupWindowParams += showDuplicatesAction_CustomizePopupWindowParams; } private void showDuplicatesAction_CustomizePopupWindowParams(object sender, CustomizePopupWindowParamsEventArgs e) { var duplicatesDictionary = GetDuplicatesDictionary(); var nonPersistentObjectSpace = Application.CreateObjectSpace<DuplicatesList>(); var duplicatesList = CreateDuplicatesList(duplicatesDictionary, nonPersistentObjectSpace); e.View = Application.CreateDetailView(nonPersistentObjectSpace, duplicatesList); e.DialogController.SaveOnAccept = false; e.DialogController.CancelAction.Active["NothingToCancel"] = false; } private Dictionary<string, int> GetDuplicatesDictionary() { var dictionary = new Dictionary<string, int>(); foreach(Book book in View.CollectionSource.List) { if(string.IsNullOrWhiteSpace(book.Title)) continue; dictionary[book.Title] = dictionary.GetValueOrDefault(book.Title) + 1; } return dictionary; } private DuplicatesList CreateDuplicatesList(Dictionary<string, int> duplicatesDictionary, IObjectSpace objectSpace) { DuplicatesList duplicatesList = objectSpace.CreateObject<DuplicatesList>(); foreach(var (title, count) in duplicatesDictionary) { if(count <= 1) continue; var duplicate = objectSpace.CreateObject<Duplicate>(); duplicate.Title = title; duplicate.Count = count; duplicatesList.Duplicates.Add(duplicate); } objectSpace.CommitChanges(); return duplicatesList; } } }

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.