Ways to Add a Business Class
- 3 minutes to read
This topic describes how to add a business class to your application’s data model.
Code First
You can implement business classes from scratch or import them from external modules.
Implement a Business Class from Scratch
Refer to the following help topics for information on how to implement business model with your ORM:
Import Classes from a Business Class Library or Module
Note
XPO:
When you add a class to the data model, all the referenced classes are also added.
EF Core:
When you add a class to the data model, you should register all the business class’ ancestors and referenced classes.
You can use existing classes from a Business Class Library or module. For this purpose, reference the assembly with these classes in a MySolution.Module project.
Import All Classes from an Assembly (In Code)
using DevExpress.ExpressApp;
//...
public sealed class MySolutionModule : ModuleBase {
public MySolutionModule() {
//...
AdditionalExportedTypes.AddRange(
ModuleHelper.CollectExportedTypesFromAssembly(
typeof(MyNamespace.MyModule).Assembly, ExportedTypeHelpers.IsExportedType));
}
}
Import Select Classes from an Assembly (In Code)
using DevExpress.ExpressApp;
using DevExpress.Persistent.BaseImpl;
//...
public sealed class MySolutionModule : ModuleBase {
public MySolutionModule() {
//...
AdditionalExportedTypes.AddRange(
new Type[] { typeof(Address), typeof(Note) });
}
}
If you use EF Core, add all the new classes and their ancestors to the solution’s DbContext.
using MySolutionModule.BusinessObjects;
namespace MySolutionModule.BusinessObjects {
public class MySolutionDbContext : DbContext {
//...
public DbSet<Address> Addresses { get; set; }
public DbSet<Note> Notes { get; set; }
}
}
Modify a Class from a Business Class Library or Module
You can modify a class from a Business Class Library or module in one of the following ways:
Inherit from the class.
Step-by-step instructions:
- Modify the information on the class loaded to the Application Model. For this purpose, invoke the Model Editor and navigate to the corresponding BOModel | <Class> node.
Model First (XPO)
You can use the XPO Data Model Designer to build your application data model in a visual designer and generate the code of underlying business classes.
Step-by-step instructions: How to: Create a Business Model in the XPO Data Model Designer.
Database First
If you already have a database with a set of tables, you can generate business classes that correspond to these tables.
Step-by-step instructions:
- XPO: How to: Generate XPO Business Classes for Existing Data Tables.
- EF Core: Generate EF Core Business Classes from an Existing Database for .NET Blazor and WinForms Applications (Database First)