How to: Add a New Detail Collection

  • 3 minutes to read

This document describes how to add a new detail collection to an application generated with the DevExpress Scaffolding Wizard. It supports editing detail collections (one-to-many relations). If such collections exist in a data source, the master object's panel will contain additional GridControl controls displaying child objects.

This topic contains the following sections.

The complete sample project (the result of this current tutorial) is available at:

Task Details

In this topic, you will extend this example: http://www.devexpress.com/example=T322553. The example is built in the context of the UI Generation (Code First) tutorial.

The data model in this example contains the Department table.

public class Department {
    public Department() {
        Courses = new HashSet<Course>();
    }
    public int DepartmentID { get; set; }
    public string Name { get; set; }
    public virtual ICollection<Course> Courses { get; set; }
}

The Department table contains the Courses detail collection, which is shown in the UI.

sc-ex1-001

This tutorial describes how to add a new detail collection into the Department table - Employees. The resulting UI is shown below.

sc-ex1-005

Extend Model

Add the Employees property to the Department class.

public class Department {
    public Department() {
        Courses = new HashSet<Course>();
        Employees = new HashSet<Employee>();
    }
    public int DepartmentID { get; set; }
    public string Name { get; set; }
    public virtual ICollection<Course> Courses { get; set; }
    public virtual ICollection<Employee> Employees { get; set; }
}

Regenerate ViewModels and Views

Now, when the model is updated, you can regenerate ViewModels and Views.

Open the Template Gallery.

sc-ex1-010

Run the Scaffolding Wizard and follow its steps.

In the finish dialog, you can select which ViewModels and Views should be regenerated. In the current scenario, you need to select the ViewModel and View for the Department entity, and also all ViewModels and Views for related entities.

sc-ex1-015

Result

If you run the application, you will see the Employee detail view has been added to the Department editing form.

sc-ex1-005