Skip to main content

Class Structure

  • 4 minutes to read

This article describes what files and folders the Scaffolding Wizard adds to your project. All classes mentioned in this document are grouped by application layers to which these classes correspond. Refer to the Application Layers document to learn about major layers in applications generated by the Wizard. The WinForms MVVM section gives the theory behind each layer and explains the main concepts and advantages of a multi-layer development pattern.

Data Model Layer

Data Model layer obtains and manipulates persistent data. Classes that implement this layer are stored within the [DbContext_Name]DataModel folder. The figure below illustrates Data Model classes generated for the sample Northwind2010Entities DbContext.

Scaffolding - Classes - Data Model

Classes of this layer implement UnitOfWork and Repository concepts.

  • A UnitOfWork is a transaction that provides access to Repositories and tracks any changes made to these Repositories.
  • A Repository is a collection of entities (data records) or a specific type. Each Repository is owned by the UnitOfWork that created it. The same UnitOfWork is used to commit changes made to a Repository back to the database.

The fundamental UnitOfWork concept is declared in the DevExpress.Mvvm.DataModel.IUnitOfWork interface. Scaffolding Wizard creates its own IUnitOfWork descendant for each application. This descendant contains Repositories specific to this specific application. In the figure above, this descendant is called INorthwind2010EntitiesUnitOfWork. The Northwind2010EntitiesUnitOfWork class in the same figure is the runtime implementation of this IUnitOfWork descendant. This class also creates instances of IRepository/IReadOnlyRepository interfaces, which declare the Repository concept.

Finally, the auto-generated UnitOfWorkSource class contains one single method - GetUnitOfWorkFactory(). This method retrieves an instance of the IUnitOfWorkFactory interface, required to obtain an IUnitOfWork instance.

View Model Layer

All classes that implement View Models are POCO classes, which allows you to use simplified syntax for bindings and notifications. Moreover, void methods declared in these classes are automatically treated by the MVVM Framework as bindable commands.

View Model classes generated by Scaffolding Wizard are placed into the “ViewModels” folder of your project. This folder contains sub-folders named after individual data source tables and views. The figure below illustrates an example.

Scaffolding - Classes - View Models

There are three types of View Models generated by Wizard.

  • Collection View Model

    View Models of this type work with collections of entities. Names of these View Models include the word “Collection”.

  • Single Object View Model

    These View models operate individual data records (entities) of a specific type. Scaffolding Wizard does not generate such View Models for read-only data source tables and views.

  • Main View Model

    This View Model is placed directly to the “ViewModels” folder and is named after the DbContext. Initializes all application modules and provides the OnActiveModuleChanged method to track end-user navigation.

The “Common” folder contains four more View Models. These serve as base classes for individual View Models generated by Wizard and provide the entry point for adding custom properties, commands and override methods without modifying the auto-generated code.

  • SingleObjectViewModel

    Serves as a base class for all single object View Models and provides members to perform CRUD operations on these entities. These members are derived from the DevExpress.Mvvm.ViewModel.SingleObjectViewModelBase class.

  • CollectionViewModel

    The base class for collection View Models, generated for data source tables and views that can be modified. Derives the DevExpress.Mvvm.ViewModel.CollectionViewModelBase and DevExpress.Mvvm.ViewModel.ReadOnlyCollectionViewModelBase classes.

  • ReadOnlyCollectionViewModel

    This class serves as a base class for read-only data source tables and views. Derives the DevExpress.Mvvm.ViewModel.ReadOnlyCollectionViewModelBase class.

  • EntitiesViewModel

    Provides loading data records (entities) to collection View Models.

View Layer

Scaffolding Wizard organizes generated Views very similarly to View Models. Views are also stored in the corresponding project folder that contains a number of sub-folders named after data source tables and views. Each sub-folder contains at least one View that displays the entire entities collection. If the corresponding data set is not read-only, this sub-folder also contains the single object View for modifying individual entities. The main View is located directly in the “Views” folder.

Each View is an XtraUserControl object. Depending on the selected UI type, these User Controls are displayed within separate forms or child NavigationPage containers.

To learn more about embedded runtime functionality provided by auto-generated Views, refer to the Embedded Functionality article.