With XAF, you can build new applications from scratch or maintain existing databases. The How to: Generate XPO Business Classes for Existing Data Tables topic describes how to use the design-time wizard that generates business classes for one or more data tables in the specified database at the same time. Additionally, the existing database can contain views (stored queries), which need to be accessed in an XAF application's List Views, Analysis, and Reports. If the database view has a key column, you can map a persistent class to it using the same approach as mapping to a regular table.

使用 XAF,您可以从头开始构建新应用程序或维护现有数据库。"如何:为现有数据表生成 XPO 业务类"主题介绍如何使用设计时向导,该向导同时为指定数据库中的一个或多个数据表生成业务类。此外,现有数据库可以包含需要在 XAF 应用程序的列表视图、分析和报表中访问的视图(存储的查询)。如果数据库视图具有键列,则可以使用与映射到常规表相同的方法将持久类映射到该列。

This topic describes how to implement a persistent class mapped to a database view without a key. We used the "Northwind Traders" demo database, shipped with DXperience Suite and installed in %PUBLIC%\Documents\DevExpress Demos 19.2 \Components\Data\nwind.mdb by default, in this topic. Besides tables filled with demo data, this database includes several database views.

本主题介绍如何实现映射到没有键的数据库视图的持久类。我们使用"北风交易者"演示数据库,在本主题中随 DXperience 套件一起出厂并安装于 %PUBLIC%_文档_DevExpress 演示 19.2 [组件]Datanwind.mdb。本主题中。除了填充演示数据的表外,此数据库还包括多个数据库视图。

Note 注意
This approach uses composite keys, which are not supported in the Mobile applications, and works only for WinForms and ASP.NET applications.
此方法使用移动应用程序中不支持的复合键,并且仅适用于 WinForms 和ASP.NET应用程序。

1.Create a new XAF solution and follow the steps from the How to: Generate XPO Business Classes for Existing Data Tables topic. Do not forget to modify the connection string that connects your application to the nwind.mbd database.

创建新的 XAF 解决方案,并按照"如何:为现有数据表生成 XPO 业务类"主题中的步骤进行操作。不要忘记修改将应用程序连接到 nwind.mbd 数据库的连接字符串。

2.Open the nwind.mbd database to see what views (queries) it contains. You can use Microsoft Office Access or any other MDB viewer application. In this example, the CustomerReports view is mapped to the CustomerReports persistent class:

打开 nwind.mbd 数据库以查看它包含哪些视图(查询)。您可以使用 Microsoft Office 访问或任何其他 MDB 查看器应用程序。在此示例中,客户报告视图映射到客户报告持久性类:

Note 注意
This view contains the ProductName, CompanyName, OrderDate and ProductAmount fields. These names are used when implementing the CustomerReports class.
此视图包含"产品名称、公司名称、订单日期"和"产品金额"字段。在实现客户报告类时使用这些名称。

3.Create a new CustomerReports persistent class (you can use the DevExpress 19.2 ORM Persistent Object template). Replace the automatically generated class declaration with the following code:

创建新的客户报告持久性类(您可以使用 DevExpress 19.2 ORM 持久对象模板)。将自动生成的类声明替换为以下代码:

using DevExpress.ExpressApp.Xpo.Utils;
using DevExpress.Persistent.Base;
using DevExpress.Xpo;
// ...
[DefaultClassOptions]
public class CustomerReports : XPLiteObject {
public CustomerReports(Session session) : base(session) { }
CustomerReportsViewKey fKey;
[Key, Persistent, Browsable(false)]
public CustomerReportsViewKey Key {
get { return fKey; }
set { SetPropertyValue(nameof(Key), ref fKey, value); }
}
public string ProductName { get { return Key.ProductName; } }
public string CompanyName { get { return Key.CompanyName; } }
public DateTime OrderDate { get { return Key.OrderDate; } }
public string ProductAmount { get { return Key.ProductAmount; } }
}
[TypeConverter(typeof(StructTypeConverter<CustomerReportsViewKey>))]
public struct CustomerReportsViewKey {
string fProductName;
[Persistent("ProductName"), Browsable(false)]
public string ProductName {
get { return fProductName; }
set { SetPropertyValue(nameof(ProductName), ref fProductName, value); }
}
string fCompanyName;
[Persistent("CompanyName"), Browsable(false)]
public string CompanyName {
get { return fCompanyName; }
set { SetPropertyValue(nameof(CompanyName), ref fCompanyName, value); }
}
DateTime fOrderDate;
[Persistent("OrderDate"), Browsable(false)]
public DateTime OrderDate {
get { return fOrderDate; }
set { SetPropertyValue(nameof(OrderDate), ref fOrderDate, value); }
}
string fProductAmount;
[Persistent("ProductAmount"), Browsable(false)]
public string ProductAmount {
get { return fProductAmount; }
set { SetPropertyValue(nameof(ProductAmount), ref fProductAmount, value); }
}
}

Each persistent class requires a primary key. The CustomerReports class is an XPLiteObject class descendant, which has no auto-generated key property. So, the Key property representing a composite key (a key formed by combining at least two or more columns) was implemented.

每个持久类都需要一个主键。CustomerReports 类是 XPLiteObject 类后代,没有自动生成的密钥属性。因此,实现了表示复合键的 Key 属性(通过组合至少两个或多个列而形成的键)。

The CustomerReportsViewKey struct defines columns which form a composite key. The struct requires the TypeConverter attribute, which enables ASPxGridView to recognize the key value and to process objects.

客户报告视图密钥结构定义构成复合键的列。结构需要 TypeConverter 属性,该属性使 ASPxGridView 能够识别键值并处理对象。

Additionally, the CustomerReports class exposes properties corresponding to all the view's columns. You can omit any property, but the composite key should still include all columns.

此外,CustomerReports 类公开与所有视图列对应的属性。可以省略任何属性,但复合键仍应包含所有列。

Note 注意
  • A database view can already have a key column. In this case, you do not need the composite key, and you should decorate the key property with the KeyAttribute.
  • The number of columns included in the composite key is limited. For instance, Microsoft SQL Server allows a maximum of 16 columns.
  • 数据库视图可以具有键列。在这种情况下,不需要复合键,并且应该使用 KeyAttribute 装饰该键属性。
  • 复合键中包含的列数受到限制。例如,Microsoft SQL Server 最多允许 16 列。

If you do not want your class to have the same name as the database view, you can use a custom name, and decorate the class with the PersistentAttribute:

如果不希望类具有与数据库视图相同的名称,则可以使用自定义名称,并使用持久属性装饰类:

[DefaultClassOptions, Persistent("CustomerReports")]
public class MyCustomerReports : XPLiteObject {
// ...
}

4.Run the application. The "Customer Reports" object is available.

运行应用程序。"客户报告"对象可用。

You can use the CustomerReports class as the Data Type in Reports V2 and Analysis:

您可以将客户报告类用作报表 V2 和分析中的数据类型:

 

How to: Map a Persistent Class to a Database View Which Has No Key Field如何:映射持久化类到无主键数据库视图的更多相关文章

  1. NHibernate官方文档中文版——持久化类(Persistent Classes)

    持久化类是一个应用程序中的类,主要用来实现业务逻辑(例如,在电商应用中的客户和订单类).持久化类,就像它的名字一样,生命周期短暂并且用来持久化的据库对象实例. 如果这些类的构造能够依照一些简单的原则, ...

  2. mybatis resultType=map时,value为null时返回结果没有对应的key

    mybatis.xml 配置文件设置 <configuration> <settings> <!-- 在null时也调用 setter,适应于返回Map,3.2版本以上可 ...

  3. [NHibernate]持久化类(Persistent Classes)

    系列文章 [Nhibernate]体系结构 [NHibernate]ISessionFactory配置 引言 持久化类是应用程序用来解决商业问题的类(比如,在电子交易程序中的Customer和Orde ...

  4. How to: Implement a Custom Base Persistent Class 如何:实现自定义持久化基类

    XAF ships with the Business Class Library that contains a number of persistent classes ready for use ...

  5. 第51节:Java当中的集合框架Map

    简书作者:达叔小生 Java当中的集合框架Map 01 Map提供了三个集合视图: 键集 值集 键-值 映射集 public String getWeek(int num){ if(num<0 ...

  6. Java当中的集合框架Map

    简书作者:达叔小生 Java当中的集合框架Map 01 Map提供了三个集合视图: 键集 值集 键-值 映射集 public String getWeek(int num){ if(num<0 ...

  7. Map的底层实现原理

    一,前言 1.1,概述 ​ 现实生活中,我们常会看到这样的一种集合:IP地址与主机名,身份证号与个人,系统用户名与系统用户对象等,这种一一对应的关系,就叫做映射(K-V).Java提供了专门的集合类用 ...

  8. javaSE学习笔记(11)--- Map

    javaSE学习笔记(11)--- Map 1.Map集合 现实生活中,我们常会看到这样的一种集合:IP地址与主机名,身份证号与个人,系统用户名与系统用户对象等,这种一一对应的关系,就叫做映射.Jav ...

  9. 01 语言基础+高级:1-6 集合_day04【Map】

    day04 [Map] 主要内容 Map集合 教学目标 能够说出Map集合特点 使用Map集合添加方法保存数据 使用”键找值”的方式遍历Map集合 使用”键值对”的方式遍历Map集合 能够使用Hash ...

随机推荐

  1. gulp+webpack+angular1的一点小经验(第一部分gulp与webpack的整合)

    时间匆匆如流水继上周熟悉了gulp的初步安装与环境配置以后,我的项目又进入了新的阶段! 这篇文章将把我这一周遇到的一些问题,以及解决的方式做一个小小的总结,不一定记的完整,但都是个人的一点经验,分享给 ...

  2. Vue3.0常用代码片段和开发插件

    Vue3 Snippets for Visual Studio Code Vue3 Snippets源码 Vue3 Snippets下载 This extension adds Vue3 Code S ...

  3. BZOJ1001: [BeiJing2006]狼抓兔子(优化的dinic或转化对偶图求最短路)

    1001: [BeiJing2006]狼抓兔子 Time Limit: 15 Sec  Memory Limit: 162 MBSubmit: 30078  Solved: 7908[Submit][ ...

  4. 开通博客第一天,记录此时此刻,开始学习加强c#

    从2017年6月毕业到现在,不断的学习.net,在工作中不断的加强技术,终于在此时此刻决定开通博客,记录此后每一天学习的技术点,两年来,每天所涉及的技术点很杂,学了这个忘了那个,总感觉在进步却总是觉得 ...

  5. 使用iCamera 测试MT9F002 1400w高分辨率摄像头小结 之!!看清细节!!!

    使用iCamera 测试MT9F002 1400w高分辨率摄像头小结 之!!看清细节!!! 本方案测试两种种分辨率输出(其他更多分辨率设置,可以参考手册配置) 4608*3288=1515万像素 11 ...

  6. 【Flutter】372- Flutter移动端实战手册

    ☝点击上方蓝字,关注我们! 本文字数:3705字 预计阅读时间:28分钟 导 读 Flutter又双叒叕来了!本周推送是我们Flutter系列文章的最终篇!<Flutter移动端实战手册> ...

  7. Mechanical Design Optimization with Abaqus and Isight

    一.项目背景 本项目为"ME327机械优化设计方法"课程项目. 如何合理利用更轻更强的材料,是机器人结构设计值得深究的问题.在驱动的功率一定的情况下,更轻的机械结构意味着电机承受更 ...

  8. 大数据学习笔记——Java篇之网络编程基础

    Java网络编程学习笔记 1. 网络编程基础知识 1.1 网络分层图 网络分层分为两种模型:OSI模型以及TCP/IP网络模型,前者模型分为7层,是一个理论的,参考的模型:后者为实际应用的模型,具体对 ...

  9. nyoj 737 石子合并(区间DP)

    737-石子合并(一) 内存限制:64MB 时间限制:1000ms 特判: No通过数:28 提交数:35 难度:3 题目描述:     有N堆石子排成一排,每堆石子有一定的数量.现要将N堆石子并成为 ...

  10. 《MySQL数据库》常用语法(二)

    表关联关系: -- 内联接 SELECT * FROM m INNER JOIN n ON m.id = n.id; -- 左外联接 SELECT * FROM m LEFT JOIN n ON m. ...