How to: Add a New Detail Collection
- 2 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.
Task Details
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.
This tutorial describes how to add a new detail collection into the Department table - Employees. The resulting UI is shown below.
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.
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.
Result
If you run the application, you will see the Employee detail view has been added to the Department editing form.