In this topic, you will learn how to use the Upcasting feature of XPO in XAF. It is useful when you need to combine base and derived classes in a single query.

在本主题中,您将学习如何在 XAF 中使用 XPO 的转换功能。当您需要在单个查询中合并基类和派生类时,它很有用。

Tip 提示
Upcasting is not supported in Mobile applications.
移动应用程序不支持向上转换。

The following business model will be implemented to demonstrate the UpCasting.

将实现以下业务模型来演示 UpCasting。

The code below describes the persistent class hierarchy:

下面的代码描述了持久性类层次结构:

  1. [DefaultClassOptions]
  2. [System.ComponentModel.DefaultProperty(nameof(Title))]
  3. public class Department : BaseObject {
  4. private string title;
  5. private string office;
  6. public Department(Session session) : base(session) {}
  7. public string Title {
  8. get {return title;}
  9. set {
  10. SetPropertyValue(nameof(Title), ref title, value);
  11. }
  12. }
  13. public string Office {
  14. get {return office;}
  15. set {
  16. SetPropertyValue(nameof(Office), ref office, value);
  17. }
  18. }
  19. [Association("Department-Employees")]
  20. public XPCollection<EmployeeBase> Employees {
  21. get {return GetCollection<EmployeeBase>(nameof(Employees));}
  22. }
  23. }
  24.  
  25. public class EmployeeBase : BaseObject {
  26. public EmployeeBase(Session session) : base(session) {}
  27. private string name;
  28. private string email;
  29. public string Name {
  30. get {return name;}
  31. set {
  32. SetPropertyValue(nameof(Name), ref name, value);
  33. }
  34. }
  35. public string Email {
  36. get {return email;}
  37. set {
  38. SetPropertyValue(nameof(Email), ref email, value);
  39. }
  40. }
  41. private Department department;
  42. [Association("Department-Employees")]
  43. public Department Department {
  44. get {return department;}
  45. set {
  46. SetPropertyValue(nameof(Department), ref department, value);
  47. }
  48. }
  49. }
  50.  
  51. [DefaultClassOptions]
  52. public class LocalEmployee : EmployeeBase {
  53. public LocalEmployee(Session session): base(session) {}
  54. private string insurancePolicyNumber;
  55. public string InsurancePolicyNumber {
  56. get {return insurancePolicyNumber;}
  57. set {
  58. SetPropertyValue(nameof(InsurancePolicyNumber), ref insurancePolicyNumber, value);
  59. }
  60. }
  61. }
  62.  
  63. [DefaultClassOptions]
  64. public class ForeignEmployee : EmployeeBase {
  65. public ForeignEmployee(Session session): base(session) {}
  66. private DateTime visaExpirationDate;
  67. public DateTime VisaExpirationDate {
  68. get {return visaExpirationDate;}
  69. set {
  70. SetPropertyValue(nameof(VisaExpirationDate), ref visaExpirationDate, value);
  71. }
  72. }
  73. }

In the code above, the Department, LocalEmployee and ForeignEmployee classes use the DefaultClassOptions attribute. To learn more, refer to the Data Annotations in Data Model topic.

在上面的代码中,部门、本地员工和外籍员工类使用默认类选项属性。要了解更多信息,请参阅数据模型中的数据注释主题。

Now, run the application (whether the Windows Forms or ASP.NET Web application). Invoke a Department Detail View:

现在,运行该应用程序(无论是 Windows 窗体还是ASP.NET Web 应用程序)。调用部门详细信息视图:

The nested Employees List View displays the properties of the EmployeeBase class only. This behavior is by design. However, it is better to display Employee class descendant specific properties in the Employees List View. With the UpCasting feature, this is accomplished with ease.

嵌套员工列表视图仅显示员工基础类的属性。此行为是设计使然。但是,最好在"员工列表"视图中显示员工类后代特定属性。使用"向上转换"功能,可以轻松完成。

To add required columns to the List View that represents the Department.Employees collection, invoke the Model Editor. Locate the Views | Department_Employees_ListView | Columns node. Add two additional child nodes via the context menu. Specify their PropertyName property by the following values:

  • <LocalEmployee>InsurancePolicyNumber
  • <ForeignEmployee>VisaExpirationDate

要将所需列添加到表示部门.员工集合的列表视图,请调用模型编辑器。查找视图 |Department_Employees_ListView |列节点。通过上下文菜单添加两个额外的子节点。按以下值指定其属性名属性:

  • <LocalEmployee>保险单编号
  • <ForeignEmployee>签证过期日期

These values will be recognized by XPO, and the LocalEmployee.InsurancePolicyNumber and ForeignEmployee.VisaExpirationDate properties will be displayed for objects retrieved from the database to the Department.Employees collection.

这些值将由 XPO 和本地员工.保险政策编号和外国雇员.Visa过期日期属性显示从数据库检索到部门的对象。

In addition, set the "Insurance Policy Number" and "Visa Expiration Date" values to the Caption property of the newly added columns.

此外,将"保险单编号"和"签证到期日期"值设置为新添加列的"标题"属性。

Run the application and invoke the Department Detail View once again:

运行应用程序并再次调用部门详细信息视图:

You can see that the properties of the EmployeeBase class descendants are displayed together with the EmployeeBase class properties.

您可以看到,EmployerBase 类后代的属性与 EmployerBase 类属性一起显示。

How to: Use XPO Upcasting in XAF 如何:在 XAF 中使用 XPO 强制转换的更多相关文章

  1. XAF 如何将数据库中Byte array图片显示出来

    问题比较简单,直接上代码. private Image _Cover; [Size(SizeAttribute.Unlimited), ValueConverter(typeof(ImageValue ...

  2. [原] XAF 如何将数据库中Byte array图片显示出来

    问题比较简单,直接上代码. private Image _Cover; [Size(SizeAttribute.Unlimited), ValueConverter(typeof(ImageValue ...

  3. How to: Use Both Entity Framework and XPO in a Single Application 如何:在单个应用程序中同时使用实体框架和 XPO

    This topic demonstrates how to create a simple XAF application that uses both the Entity Framework ( ...

  4. [XAF] How to improve the application's performance

    [自己的解决方案]数据量大时,可显著提升用户使用体验! 1.Root ListView 参考官方的E1554 点击导航菜单后首先跳出查询条件设置窗体进行设置 可设置查询方案或查询方案的查询条件,排序字 ...

  5. XAF学习资源整合大全

    近期有很多XAF初学者与我联系,我多数时间在重复很多入门问题,所以决定整理一篇XAF资源列表,方便大家查找资料,也请知晓其他资源的人留言或与我联系,我将新资源追加到本篇文章中,方便更多人. 一.本博客 ...

  6. XAF应用开发教程(六)控制器

    是的,XAF也是MVC结构的,但不仅限于MVC,ViewModel也存在,它是一项复合技术,AOP,ORM,MVC都有. 真实运行的系统中,仅有增删改查功能肯定是远远不够的,ERP.CRM等系统的开发 ...

  7. XAF应用开发教程(二)业务对象模型之简单类型属性

    使用过ORM的朋友对这一部分理解起来会非常快,如果没有请自行补习吧:D. 不说废话,首先,我们来开发一个简单的CRM系统,CRM系统第一个信息当然是客户信息.我们只做个简单 的客户信息来了解一下XAF ...

  8. XAF_GS_02_创建第一个XAF项目

    上一节我们讲解了如何安装XAF环境,这次我们要开始创建一个自己的XAF项目. Setp 1 第一步打开你的Visual Studio,新建项目,如下图所示,选择DevExpress XAF,选择好你的 ...

  9. [XAF] Llamachant Framework Modules

    Llamachant Framework Modules 最近更新 2018-08-22 *变更:我们从所需的模块列表中删除了审计跟踪模块.如果要在应用程序中使用Audit Trail功能,请将Aud ...

随机推荐

  1. 基本shell脚本

    #!/bin/bash attr=() num= while true do read -p ">>input:" name attr[$num]=$name echo ...

  2. Python 命令行之旅:深入 click 之增强功能

    作者:HelloGitHub-Prodesire HelloGitHub 的<讲解开源项目>系列,项目地址:https://github.com/HelloGitHub-Team/Arti ...

  3. 吴裕雄--天生自然python学习笔记:python通过“任务计划程序”实现定时自动下载或更新运行 PM2.5 数据抓取程序数据

    在 Windows 任务计划程序中,设置每隔 30 分钟自动抓取 PM2.5 数据,井保存 在 SQLite 数据库中 . import sqlite3,ast,requests,os from bs ...

  4. “Unknown class XXViewController in Interface Builder file.”问题处理

    在静态库中写了一个XXViewController类,然后在主工程的xib中,将xib的类指定为XXViewController,程序运行时,报了如下错误: “Unknown class XXView ...

  5. poj3111 K Best 最大化平均值,二分

    题目:http://poj.org/problem?id=3111 题意:给你n,k,n个数的v.w值,选出k个数,使得v之和/w之和最大化. 思路:一看到题目,这不是赤果果的贪心吗?为什么放在二分专 ...

  6. 上手spring boot项目(三)之spring boot整合mybatis进行增删改查

    使用mybatis框架进行增删改查大致有两种基础方式,一种扩展方式.两种基础方式分别是使用xml映射文件和使用方法注解.扩展方式是使用mybatis-plus的方式,其用法类似于spring-data ...

  7. Python3 函数基础1

    目录 定义函数 定义函数的三种形式 空函数 有参函数 无参函数 函数的调用 函数的返回值 函数的参数 形参 (parameter) 实参(argument) 位置形参与位置实参 默认形参 关键字实参 ...

  8. Newman

    目录 简介 安装 使用 简介 Newman是为postman而生,专门用来运行postman编写好的脚本 使用Newman,你可以很方便的用命令行来执行postman collections Newm ...

  9. Butterknife Attribute value must be constant

    背景 在下面的R.id.rv_msg_remind 标红,然后鼠标附上去,显示attribute value must be contant.如下: @BindView(R.id.rv_msg_rem ...

  10. Java工作流系统jflow向工作处理器传值的方法大全

    关键词:工作流快速开发平台  工作流流设计  业务流程管理   asp.net 开源工作流 bpm工作流系统  java工作流主流框架  自定义工作流引擎 表单设计器  流程设计器 在启动开始节点时, ...