expressappframework-112847-business-model-design-orm-ways-to-add-a-business-class.md
This topic describes how to add a business class to your application’s data model.
You can implement business classes from scratch or import them from external modules.
Refer to the following help topics for information on how to implement business model with your ORM:
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.
using DevExpress.ExpressApp;
//...
public sealed class MySolutionModule : ModuleBase {
public MySolutionModule() {
//...
AdditionalExportedTypes.AddRange(
ModuleHelper.CollectExportedTypesFromAssembly(
typeof(MyNamespace.MyModule).Assembly, ExportedTypeHelpers.IsExportedType));
}
}
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; }
}
}
You can modify a class from a Business Class Library or module in one of the following ways:
Inherit from the class.
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.
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.
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:
See Also