Ways to Add a Business Class(添加业务类的方法)
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:
有关如何使用ORM实现业务模型的信息,请参阅以下帮助主题:
- Implement Custom Business Classes (EF Core).
实现自定义业务类(EF Core)。
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.
您可以使用业务类库或模块中的现有类。为此,请在MySolutions. Module项目中使用这些类引用程序集。
Import All Classes from an Assembly (In Code)(从程序集导入所有类(在代码中))
C#
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)(从程序集导入选择类(在代码中))
C#
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.
如果您使用EF Core,请将所有新类及其祖先添加到解决方案的DbContext。
C#
using MySolutionModule.BusinessObjects;
namespace MySolutionModule.BusinessObjects {
public class MySolutionDbContext : DbContext {
//...
public DbSet<Address> Addresses { get; set; }
public DbSet<Note> Notes { get; set; }
}
}
Import Classes Using the Module Designer (.NET Framework)(使用模块设计器(. NET Framework)导入类)
The Module Designer’s Exported Types section lists all assemblies that contain business classes in the Referenced Assemblies node. To add a class to the UI construction process, right-click the class and select Use Type in Application.
模块设计器的导出类型部分列出了引用程序集节点中包含业务类的所有程序集。要将类添加到UI构建过程,请右键单击该类并选择在应用程序中使用类型。
Note
If you add a module to the Designer’s Required Modules section, its business classes are used in the UI construction process and appear in the Application Model. You cannot change this behavior.
如果您将模块添加到Designer’s必需模块部分,则其业务类将在UI构建过程中使用并出现在应用程序模型中。您不能更改此行为。
To add all the classes from an assembly, select the assembly and press Space.
要从程序集中添加所有类,请选择程序集并按Space。
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:
分步说明:- Implement Custom Business Classes (EF Core).
实现自定义业务类(EF Core)。
- Implement Custom Business Classes (EF Core).
- Recompile the XAF Business Class Library.
重新编译XAF业务类库。
Step-by-step instructions: Built-in Business Classes & Interfaces.
分步说明:内置业务类和接口。 - 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.
修改加载到应用程序模型的类的信息。为此,调用模型编辑器并导航到相应的BOModel|<Class>节点。
Model First (XPO)(模型优先(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.
您可以使用XPO数据模型设计器在可视化设计器中构建应用程序数据模型并生成底层业务类的代码。
Step-by-step instructions: How to: Create a Business Model in the XPO Data Model Designer.
分步说明:如何:在XPO数据模型设计器中创建业务模型。
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.
XPO:如何:为现有数据表生成XPO业务类。 - EF Core: Generate EF Core Business Classes from an Existing Database for .NET Blazor and WinForms Applications (Database First)
EF Core:从现有数据库生成EF Core业务类。NET Blazor和WinForms应用程序(数据库优先)