In this lesson, you will learn how to implement business classes for your application using the Business Class Library. This library contains the most typical ready-to-use business classes. You will implement a custom Contact class by deriving from the Person class available in this library, and implement several additional properties. You will also learn the basics of automatic user interface construction based on data.

在本课中,您将学习如何使用 Business 类库为应用程序实现业务类。此库包含最典型的即用型业务类。您将通过从此库中可用的 Person 类派生来实现自定义联系人类,并实现多个附加属性。您还将学习基于数据的自动用户界面构造的基础知识。

  • Typically, business classes should be implemented in a platform-independent module project, so that the same objects will be available in both WinForms and ASP.NET applications. To add a new class, right-click the Business Objects folder in the MySolution.Module project, and choose Add | Class... to invoke the Add New Item dialog. In this dialog, specify "Contact" as the new item's name and click Add. As a result, you will get an automatically generated code file with a single class declaration.

  • 通常,业务类应在独立于平台的模块项目中实现,以便 WinForms 和ASP.NET应用程序中都提供相同的对象。要添加新类,请右键单击 MySolution.模块项目中的"业务对象"文件夹,然后选择"添加 |类。。。以调用"添加新项"对话框。在此对话框中,将"联系人"指定为新项目的名称,然后单击"添加"。因此,您将获得一个自动生成的代码文件,其中只有一个类声明。

  • Replace the automatically generated class declaration with the following code.

  • 将自动生成的类声明替换为以下代码。

    1. using System;
    2. using DevExpress.ExpressApp.DC;
    3. using DevExpress.Persistent.Base;
    4. using DevExpress.Persistent.BaseImpl.EF;
    5.  
    6. namespace MySolution.Module.BusinessObjects {
    7. [DefaultClassOptions]
    8. public class Contact : Person {
    9. public Contact() { }
    10.  
    11. public string WebPageAddress { get; set; }
    12. public string NickName { get; set; }
    13. public string SpouseName { get; set; }
    14. public TitleOfCourtesy TitleOfCourtesy { get; set; }
    15. public DateTime? Anniversary { get; set; }
    16. [FieldSize()]
    17. public String Notes { get; set; }
    18. }
    19. public enum TitleOfCourtesy { Dr, Miss, Mr, Mrs, Ms };
    20. }

    As you can see, the Contact class ancestor is Person from the Business Class Library and several custom properties are implemented.

  • 如您所见,联系人类祖先是来自 Business 类库中的人员,并且实现了多个自定义属性。

  • Note the use of the DefaultClassOptionsAttribute attribute. In this tutorial, this attribute means that the following capabilities will be available for the Contact business class.

  • 请注意使用默认类选项属性属性。在本教程中,此属性表示以下功能将可用于联系人业务类。

  • The Contact item will be added to the main form's navigation control. When clicking this item, a List View will be displayed. This List View represents a list of objects of the Contact type.
  • The Contact item will be added to the submenu of the New () button when objects of another type are displayed in the List View. Click this item to invoke a Contact detail form and create a new Contact object.
  • The Contact objects will be provided as a data source to generate reports (see Create a Report in Visual Studio).
  • 联系人项将添加到主窗体的导航控件中。单击此项目时,将显示列表视图。此列表视图表示联系人类型的对象的列表。
  • 当另一种类型的对象显示在列表视图中时,联系人项将添加到"新建(new_dropdown_btn)"按钮的子菜单中。单击此项目可调用"联系人详细信息"窗体并创建新的"联系人"对象。
  • 联系人对象将作为数据源提供以生成报告(请参阅在 Visual Studio 中创建报表)。
  • To apply each of these options separately, use the NavigationItemAttribute, CreatableItemAttribute and VisibleInReportsAttribute attributes.

  • 要单独应用每个选项,请使用导航项属性、可操作项属性和可见中报表属性属性。
  • After the class declaration, add all new business objects to the solution's DbContex

  • 类声明后,将所有新的业务对象添加到解决方案的 DbContext
  • Since Contact is a descendant of Person, entities used in the Person class should also be registered. Edit the BusinessObjects\MySolutionDbContext.cs file as shown below.

由于"联系人"是 Person 的后代,因此还应注册 Person 类中使用的实体。编辑业务对象_MySolutionDbContext.cs 文件,如下所示。

  1. using MySolution.Module.BusinessObjects;
  2.  
  3. namespace MySolution.Module.BusinessObjects {
  4. public class MySolutionDbContext : DbContext {
  5. //...
  6. public DbSet<Contact> Contacts { get; set; }
  7. public DbSet<Party> Parties { get; set; }
  8. public DbSet<Address> Addresses { get; set; }
  9. public DbSet<Country> Countries { get; set; }
  10. public DbSet<State> States { get; set; }
  11. public DbSet<PhoneNumber> PhoneNumbers { get; set; }
  12. public DbSet<Task> AssignedTasks { get; set; }
  13. }
  14. }
  • At this step, the business model has already been declared, but if you have started the application with another version of DbContext, you will get the following error: "The model backing the 'MySolutionDbContext' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269)". To avoid this error, drop the database every time you change something in the business model (create a new class, add a new attribute to an existing class, rename a class or an attribute, etc.). To do it automatically during the debug, uncomment the following code in the MySolution.Module\Module.cs file.

  • 在此步骤中,业务模型已声明,但如果已使用另一个版本的 DbContext 启动应用程序,则将出现以下错误:"自创建数据库以来,支持"MySolutionDbContext"上下文的模型已更改。请考虑使用代码优先迁移来更新数据库 (http://go.microsoft.com/fwlink/?LinkId=238269)*。为了避免此错误,每次更改业务模型中的内容时都删除数据库(创建新类、向现有类添加新属性、重命名类或属性等)。要在调试期间自动执行此操作,请取消在 MySolution.module_module_模块.cs 文件中对以下代码进行注释。

    1. public sealed partial class MySolutionModule : ModuleBase {
    2. // Uncomment this code to delete and recreate the database each time the data model has changed.
    3. // Do not use this code in a production environment to avoid data loss.
    4. #if DEBUG
    5. static MySolutionModule() {
    6. Database.SetInitializer(new DropCreateDatabaseIfModelChanges<MySolutionDbContext>());
    7. }
    8. #endif
    9. //...
    10. }
  • Run the WinForms or ASP.NET application. You will see how the user interface is automatically generated using the specified data structures. A navigation control allows you to display the Contact list. You can customize this collection using the corresponding editors. If you click the New button or double-click an existing record, the application will show a detail form (Detail View) filled with editors for each data field.

  • 运行 WinForms 或ASP.NET应用程序。您将看到如何使用指定的数据结构自动生成用户界面。导航控件允许您显示联系人列表。您可以使用相应的编辑器自定义此集合。如果单击"新建"按钮或双击现有记录,应用程序将显示一个详细信息表单(详细信息视图),其中填充了每个数据字段的编辑器。

  • The following image demonstrates the Detail and List Views in the WinForms application.

  • 下图演示了 WinForms 应用程序中的详细信息视图和列表视图。

    Notice that many elements have been generated in an intuitive manner in very little time. The proper editors are created for data fields, and appropriate editors are used in the grid controls to display data. Note that a combo box editor has been created for Title Of Courtesy (an enumerator). Also note that captions have automatically been transformed from camel-case to space-separated strings, form titles are automatically updated, etc.

  • 请注意,许多元素是在非常少的时间内以直观的方式生成的。为数据字段创建适当的编辑器,并在网格控件中使用适当的编辑器来显示数据。请注意,已为礼貌标题(枚举器)创建了组合框编辑器。另请注意,标题已自动从骆驼大小写转换为空格分隔的字符串,表单标题会自动更新,等等。

  • You can use the grid features to show, hide and rearrange columns, and apply grouping, filtering and sorting to a List View at runtime. In the WinForms application, you can customize the editor layout on the detail form as you like at runtime. For this purpose, right-click an empty space and select Customize Layout. You can now move editors to the required positions. To learn how to customize the editor layout at design time, refer to the Customize the View Items Layout topic. Additionally, you can refer to the View Items Layout Customization and List View Column Generation topics to see how the default Detail View layout and default List View column set are generated.

  • 您可以使用网格要素来显示、隐藏和重新排列列,并在运行时对列表视图应用分组、筛选和排序。在 WinForms 应用程序中,您可以在运行时根据需要自定义详细信息窗体上的编辑器布局。为此,右键单击空白区域并选择"自定义布局"。您现在可以将编辑器移动到所需的位置。要了解如何在设计时自定义编辑器布局,请参阅自定义视图项布局主题。此外,还可以参考"查看项目布局自定义"和"列表视图列生成"主题,以查看如何生成默认"详细信息视图"布局和默认列表视图列集。

You can see the code demonstrated here in the MySolution.Module | Data | Contact.cs (Contact.vb) file of the EF Demo (Code First) installed with XAF. By default, the EF Demo (Code First) application is installed in %PUBLIC%\Documents\DevExpress Demos 19.2\Components\eXpressApp Framework\EFDemoCodeFirst.

您可以在 MySolution.模块 |数据 |Contact.cs(Contact.vb)文件与XAF一起安装的EF演示(代码优先)文件。默认情况下,EF 演示(代码优先)应用程序安装在 %PUBLIC%\Documents\DevExpress Demos 19.2\Components\eXpressApp Framework\EFDemoCodeFirst.

Inherit from the Business Class Library Class 继承自Business类(EF)的更多相关文章

  1. Add a Class from the Business Class Library从业务类库添加类(EF)

    In this lesson, you will learn how to use business classes from the Business Class Library as is. Fo ...

  2. Add a Class from the Business Class Library 从业务类库添加类 (XPO)

    In this lesson, you will learn how to use business classes from the Business Class Library as is. Fo ...

  3. How to: Recompile the Business Class Library 如何:重新编译业务类库

    The eXpressApp Framework supplies the Business Class Library that consists of three assemblies. eXpr ...

  4. 不可或缺 Windows Native (21) - C++: 继承, 组合, 派生类的构造函数和析构函数, 基类与派生类的转换, 子对象的实例化, 基类成员的隐藏(派生类成员覆盖基类成员)

    [源码下载] 不可或缺 Windows Native (21) - C++: 继承, 组合, 派生类的构造函数和析构函数, 基类与派生类的转换, 子对象的实例化, 基类成员的隐藏(派生类成员覆盖基类成 ...

  5. 在CMD窗口中使用javac和java命令进行编译和执行带有包名的具有继承关系的类

    一.背景 最近在使用记事本编写带有包名并且有继承关系的java代码并运行时发现出现了很多错误,经过努力一一被解决,今天我们来看一下会遇见哪些问题,并给出解决办法. 二.测试过程 1.父类代码 pack ...

  6. 实现Square类,让其继承自Rectangle类,并在Square类增添新属性和方法,在2的基础上,在Square类中重写Rectangle类中的初始化和打印方法

    实现Square类,让其继承自Rectangle类,并在Square类增添新属性和方法,在2的基础上,在Square类中重写Rectangle类中的初始化和打印方法 #import <Found ...

  7. C++中的类继承(2)派生类的默认成员函数

    在继承关系里面, 在派生类中如果没有显示定义这六个成员 函数, 编译系统则会默认合成这六个默认的成员函数. 构造函数. 调用关系先看一段代码: class Base { public : Base() ...

  8. Thinkphp5.0 在自己定义一个公共方法的控制器并且继承了Controller类的时候报错

    在建立网站的时候,你通常想着把一些共有的方法提取出来,放入一个控制器内,如果你是将业务逻辑写入了构造函数里面,那么就得注意了. 在thinkphp5.0当中,有一个初始化的方法,类似于构造函数,那就是 ...

  9. python装饰器、继承、元类、mixin,四种給类动态添加类属性和方法的方式(一)

    介绍装饰器.继承.元类.mixin,四种給类动态添加类属性和方法的方式 有时候需要給类添加额外的东西,有些东西很频繁,每个类都需要,如果不想反复的复制粘贴到每个类,可以动态添加. # coding=u ...

随机推荐

  1. 电商设计V1(一):软件工程设计

    软件工程设计的方式方法 多视图法: 全面分析软件方方面面的问题 尽早地发现和排除项目风险与不确定因素 从不同角度去展现要设计的软件系统 为项目进行不同的干系人提供指导: 逻辑架构描述系统功能,并指导系 ...

  2. k8s~k8s里的服务Service

    k8s用命名空间namespace把资源进行隔离,默认情况下,相同的命名空间里的服务可以相互通讯,反之进行隔离. 服务Service 1.1 Service Kubernetes中一个应用服务会有一个 ...

  3. Android 线性布局 LinearLayout

    垂直布局 vertical <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" ...

  4. DevOps工程师的成长路线图

    DevOps工程师的成长路线图 我们推崇的是 Reducing the gap between Devs and Operation teams. 来自kamranahmedse you built ...

  5. 2019年Java面试题基础系列228道(1)

    1.面向对象的特征有哪些方面? 面向对象的特征主要有以下几个方面: 抽象:抽象是将一类对象的共同特征总结出来构造类的过程,包括数据抽象和行为抽象两方面.抽象只关注对象有哪些属性和行为,并不关注这些行为 ...

  6. Redux学习及应用

    Redux学习及应用 一:Redux的来源? Redux 是 JavaScript 状态容器,提供可预测化的状态管理.Redux是由 Flux 演变而来,但受 Elm 的启发,避开了 Flux 的复杂 ...

  7. mybatis中 == 和 != 的用法

    != 的用法 <if test="xxx != null and xxx !=''"> == 的用法(相较于!=,仅需将双引号和单引号的位置换一下即可) <if ...

  8. JavaScript定时器(Timer)

    版权声明:本文为博主原创文章,未经博主允许不得转载.https://www.cnblogs.com/gaoguowen/p/11119088.html 什么是定时器 简单来说就是在一段时间间隔后执行一 ...

  9. 内存取证工具-volatility、foremost

    内存取证 1. 内存取证工具volatility 猜测dump文件的profile值 root@kali:~/CTF# volatility -f mem.vmem imageinfo Volatil ...

  10. JavaScript banner轮播 左右切换 圆点点击切换

    1.效果如下图: 2.源码如下: <!DOCTYPE html> <html lang="en"> <head> <meta charse ...