In this lesson, you will learn how to implement business classes from scratch. For this purpose, the Position business class will be implemented. This class will be used in the Contact class, implemented previously. You will also learn the basics of automatic user interface construction for referenced objects.

在本课中,您将学习如何从头开始实现业务类。为此,将实现职位业务类。此类将用于以前实现的"联系人"类。您还将学习引用对象的自动用户界面构造基础知识。

Note

Before proceeding, take a moment to review the Inherit from the Business Class Library Class (EF) lesson.

在本课中,您将学习如何从头开始实现业务类。为此,将实现职位业务类。此类将用于以前实现的"联系人"类。您还将学习引用对象的自动用户界面构造基础知识。

  • Add the Position class as shown in the Inherit from the Business Class Library Class (EF) lesson. Replace the auto-generated code with the following.

  • 添加职位类,如从业务类库类 (EF) 的继承课程所示。将自动生成的代码替换为以下内容。

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using DevExpress.Persistent.Base; namespace MySolution.Module.BusinessObjects {
    [DefaultClassOptions]
    [DefaultProperty(nameof(Title))]
    public class Position {
    public Position() {
    Contacts = new List<Contact>();
    }
    [Browsable(false)]
    public Int32 ID { get; protected set; }
    public String Title { get; set; }
    public virtual IList<Contact> Contacts { get; set; }
    }
    }

    Note that the Contact collection property is declared as virtual.

  • 请注意,联系人集合属性声明为虚拟。

  • Note

    The DefaultProperty attribute is used in the code above. This attribute is used to specify the default property of the class. You can specify the most descriptive property of your class in the DefaultProperty attribute, and its values will be displayed in the following.

    注意
    DefaultProperty 属性用于上述代码。此属性用于指定类的默认属性。您可以在 DefaultProperty 属性中指定类最具描述性的属性,其值将显示在以下内容中。

    • Detail form captions
    • The leftmost column of a List View
    • The Lookup List Views (These Views will be explained in the last step of this lesson.)
    • 详细信息表单标题
    • 列表视图的最左侧列
    • 查找列表视图(这些视图将在本课的最后一步中介绍。

    Refer to the Data Annotations in Data Model topic for additional information.

    有关详细信息,请参阅数据模型中的数据注释主题。

    Important

    You can use the XAF Business Object | EF Business Object project item template from the Template Gallery to add an entity that supports IXafEntityObject, IObjectSpaceLink and INotifyPropertyChanged interfaces, which may be useful in many scenarios.

  • Register the new class in DbContext. Edit the BusinessObjects\MySolutionDbContext.cs file as shown below.

重要
           您可以使用 XAF 业务对象 |从模板库中添加 EF 业务对象项目项模板,以添加支持 IXafEntityObject、IObjectSpaceLink 和 INotifyPropertyChanged 接口的实体,这在许多情况下可能很有用。

  • 在 DbContext 中注册新类。编辑业务对象_MySolutionDbContext.cs 文件,如下所示。
  • public class MySolutionDbContext : DbContext {
    //...
    public DbSet<Position> Positions { get; set; }
    }
  • Add the Position property to the Contact class. The following code demonstrates this.

  • 将"位置"属性添加到"联系人"类。以下代码演示了这一点。

    public class Contact : Person {
    //...
    public virtual Position Position { get; set; }
    }

    The Contact class now exposes the Position reference property. Note that this property is declared as virtual.

联系人类现在公开"位置"引用属性。请注意,此属性声明为虚拟。

  • Run the WinForms or ASP.NET application. You will see how the user interface is automatically generated using the specified data structures. The navigation control will contain a new Position item, which will allow you to access Position objects. Note that in the Contact Detail View, a lookup editor has been created for Position. In this editor, a special type of View, Lookup List View, is used. Typically, this View has a single column corresponding to the class' default property. Using the lookup editor, you can select the Position for the current Contact, and add new Position objects using the New button. In addition, you will also be able to edit the existing Position object by holding down SHIFT+CTRL and clicking the selected object.

  • 运行 WinForms 或ASP.NET应用程序。您将看到如何使用指定的数据结构自动生成用户界面。导航控件将包含一个新的"位置"项,该项将允许您访问"位置"对象。请注意,在"联系人详细信息"视图中,已为"位置"创建了查找编辑器。在此编辑器中,使用特殊类型的视图"查找列表视图"。通常,此视图具有对应于类的默认属性的单个列。使用查找编辑器,您可以选择当前联系人的位置,并使用"新建"按钮添加新"位置"对象。此外,您还可以通过按住 SHIFT_CTRL 并单击所选对象来编辑现有位置对象。

You can see the code demonstrated in this lesson in the EFDemo.Module | Data | Contact.cs (Contact.vb) and Position.cs (Position.vb) files 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.

您可以在 EFDemo.模块 |数据 |Contact.cs (Contact.vb) 和 Position.cs (位置.vb) 文件与 XAF 一起安装的 EF 演示(代码优先)。默认情况下,EF 演示(代码优先)应用程序安装在

Implement Custom Business Classes and Reference Properties实现自定义业务类和引用属性(EF)的更多相关文章

  1. Implement Custom Business Classes and Reference Properties 实现自定义业务类和引用属性(XPO)

    In this lesson, you will learn how to implement business classes from scratch. For this purpose, the ...

  2. How to: Handle Renamings and Deletions of Business Classes and their Properties 如何:处理业务类及其属性的重命名和删除

    When developing an XAF application, you may be required to rename a persistent class or property due ...

  3. Implement Dependent Reference Properties 实现从属引用属性 (XPO)

    In this lesson, you will learn how to implement properties whose values can depend on other properti ...

  4. Implement Dependent Reference Properties实现依赖引用属性 (EF)

    In this lesson, you will learn how to implement properties whose values can depend on other properti ...

  5. How to: Initialize Business Objects with Default Property Values in Entity Framework 如何:在EF中用默认属性值初始化业务对象

    When designing business classes, a common task is to ensure that a newly created business object is ...

  6. How to: Generate XPO Business Classes for Existing Data Tables 如何:为现有数据表生成 XPO 业务类

    From the Tutorial and other documentation sources, you learned how to create business classes for yo ...

  7. [Tailwind] Create Custom Utility Classes in Tailwind

    In this lesson, we learn how to generate custom utility classes in tailwind. We add new properties t ...

  8. properties文件读写工具类

    java代码: import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; ...

  9. Implement Custom Cache Dependencies in ASP.NET 1.x

    Code download available at:CuttingEdge0407.exe(128 KB)   Contents What's a Cache Dependency, Anyway? ...

随机推荐

  1. LImax服务器框架学习--安装、使用ant工具、生成limax相关代码

    一.安装ant ant 是一个将软件编译.测试.部署等步骤联系在一起加以自动化的一个工具,大多用于Java环境中的软件开发.在实际软件开发中,有很多地方可以用到ant. 首先现在一个ant安装压缩包, ...

  2. 永恒之蓝及WannaCry分析

    以下部分是我的一次大作业,写了大概有一周,拿出来凑篇博客,如果有错误的地方,还请指正.粘贴过程中可能图片有错误. 1.环境搭建及简介 1.1 实验环境 Windows 7 (靶机) Parrot(攻击 ...

  3. Gradle Java 插件

    Java 插件是构建 JVM 项目的基础,它为项目增加了很多能力,例如编译,测试,打包,发布等等. 很多插件都是基于 Java 插件实现的,例如 Android 插件. 用法 使用 id 应用插件 p ...

  4. 【性能测评】DSP库,MDK5的AC5,AC6,IAR和Embedded Studio的三角函数性能

    测试条件: 1.IAR8.30开最高等级速度优化. 2.MDK5.27正式版使用AC5开最高等级优化3,开启时间优化,测试C标准库和微库MicroLib两种. 3.MDK5.27正式版使用AC6开最高 ...

  5. IT兄弟连 HTML5教程 CSS3属性特效 2D变换2

    3  scale() 方法 通过scale() 方法,元素的尺寸会增加或减少,根据给定的宽度(X轴)和高度(Y轴)参数.缩放scale()函数让元素根据中心原点对对象进行缩放.默认值是1,因此0.01 ...

  6. STM32F407外部晶体改为25M后检测不到芯片的解决办法

    问题描述 分享一个之前遇到的STM32F4晶体频率问题,导致单片机死机的解决办法.使用一款新的F4开发板,直接使用的正点原子STM32F407工程模板代码,管脚配置正确,下载到外部晶体为25MHz的开 ...

  7. Python 和 JS 有什么相似?

    Python 是一门运用很广泛的语言,自动化脚本.爬虫,甚至在深度学习领域也都有 Python 的身影.作为一名前端开发者,也了解 ES6 中的很多特性借鉴自 Python (比如默认参数.解构赋值. ...

  8. Mybatis的PageHelper分页插件的PageInfo的属性参数,成员变量的解释,以及页面模板

    作者:个人微信公众号:程序猿的月光宝盒 //当前页 private int pageNum; //每页的数量 private int pageSize; //当前页的数量 private int si ...

  9. POI解析Excel时,如何获取单元格样式以及单元格Style的一些操作

    最近,公司运营平台需要上传Excel文件并进行解析导入数据库,在开发完成后出现了一个始料不及的生产bug,下面是具体原因: 1.在用POI解析Excel时,默认如果Excel单元格中没有数据,且单元格 ...

  10. jQuery总结02_jq的dom操作+属性操作

    一:JQuery知识点 *:JQuery的dom操作 *:获取节点.给节点添加内容 *:动态创建dom节点 比如动态创建表格等,在js里面进行完成. *删除节点 这里面的删除就是将其放在了一个地方,并 ...