一,PersistentAliasAttribute-[XPO提供]

Indicates that a property is not persistent and its value is calculated based upon the values of a specific field(s).

指示某个属性不是持久性的, 并且它的值是根据特定字段的值计算的。

The expression to be evaluated can be passed as the constructor's parameter or specified via the AliasExpression property. You can use both persistent and non-persistent fields to specify the expressions. The expression is evaluated at the server side when only persistent properties are used. When a non-persistent property is referred, XPO extracts a persistent part from an expression, sends it to the database server, and processes the rest on the client. Note that this is only possible when an operation involves object loading and won't work in XPView.

 要计算的表达式可以作为构造函数的参数传递或通过 AliasExpression 属性指定。您可以使用持久性字段和非持久域来指定表达式。当只使用持久性属性时, 在服务器端计算表达式。当引用非持久性属性时, xpo 从表达式中提取持久性部分, 将其发送到数据库服务器, 并在客户端上处理其余内容。请注意, 只有当操作涉及对象加载并且无法在 XPView 中工作时, 才可能出现这种情况。

 Example

The following code shows how to define a property as non-persistent and calculate its value based upon the values of specific persistent fields. The 'ExtendedPrice' property is marked as a non-persistent, using thePersistentAliasAttribute attribute. The expression to evaluate the property's value is specified as the attribute's parameter. In addition, the property's getter evaluates this expression using the XPBaseObject.EvaluateAliasmethod.

下面的代码演示如何将属性定义为非持久性, 并根据特定持久性字段的值计算其值。使用 PersistentAliasAttribute 属性将ExtendedPrice

属性标记为非持久性。

用于计算属性值的表达式被指定为属性的参数。此外, 该属性的 getter 使用 XPBaseObject EvaluateAliasmethod 计算此表达式。

using DevExpress.Xpo;

public class Order : XPObject {
public Order() {}
public decimal UnitPrice;
public int Qty;
public decimal Discount; [PersistentAlias("UnitPrice*Qty*(1-Discount)")]
public decimal ExtendedPrice {
get { return Convert.ToDecimal(EvaluateAlias("ExtendedPrice")); }
}
}
 

Note that while a criteria expression can return an object reference, this is not supported in all scenarios. Returning an object reference by directly referencing a property, as in the following code snippet, is fully supported.

请注意, 虽然条件表达式可以返回对象引用, 但在所有方案中不支持此项。完全支持通过直接引用属性 (如下面的代码段) 返回对象引用。

[PersistentAlias("Iif(Part is null, MyCustOrderLine.Part, Part)")]
public Part CustomPart {
get {
return (Part)EvaluateAlias("CustomPart");
}
}

In this code snippet, a Part object referenced by the Part or MyCustOrderLine.Part property will be returned correctly. However, retrieving reference properties from function and aggregation operators is not supported. So, the following persistent alias declaration will not work.

在此代码段中, Part对象引用Part或MyCustOrderLine.Part属性,部件属性将正确返回。

但是, 不支持从函数和聚合运算符检索引用属性。因此, 下列持久性别名声明将不起作用。

[PersistentAlias("Iif(Part is null, MyCustOrderLine, MyCustOrderLine2).Part")]
public Part CustomPart {
get {
return (Part)EvaluateAlias("CustomPart");
}
}

 Example

The following example shows how to apply the PersistentAliasAttribute to the DefaultAddress property. When initializing a new instance of the PersistentAliasAttribute class, the name of the field which stores theDefaultAddress property's value is specified. The mDefaultAddress field has the PersistentAttribute whose PersistentAttribute.MapTo property holds the name of the column in the data store where the field's value is stored.

下面的示例演示如何将 PersistentAliasAttribute 应用于 DefaultAddress 属性。在初始化 PersistentAliasAttribute 类的新实例时, 将指定存储 theDefaultAddress 属性值的字段的名称。mDefaultAddress 字段具有 PersistentAttribute, 其 PersistentAttribute. MapTo 是字段名。

using DevExpress.Xpo;

// ...
[Persistent("DefaultAddress")]
private string mDefaultAddress; [PersistentAlias("mDefaultAddress")]
public string DefaultAddress {
get {
return mDefaultAddress;
}
}

二,CalculatedAttribute - [XAF提供]

Applied to business class properties. Specifies an expression used to calculate the target property value in the Data View mode.

应用于业务类属性。指定用于在数据DataView 模式下计算目标属性值的表达式。

Below is an example of using the CalculatedAttribute.

using DevExpress.ExpressApp.DC;
// ...
public class Person {
// ...
public String FirstName { get; set; }
public String LastName { get; set; }
[Calculated("FirstName + ' ' + LastName")]
public String FullName {
get {
return FirstName + " " + LastName;
}
}
}

Properties, used in the Expression should be persistent to be able to run an SQL query at the database level.

在表达式中使用的属性应该是持久的, 以便能够在数据库级别运行 sql 查询。

三,CalculatedPersistentAliasAttribute - [XAF提供]

Applied to a business class. Allows you to dynamically configure a persistent alias for the target business class' property.

动态的指定计算字段的公式.

Non-persistent calculated properties for which filtering and sorting should be performed on the database level can be implemented via the PersistentAlias attribute. The PersistentAlias attribute takes a single parameter which specifies the expression used to calculate the property's value on the database server side. A persistent alias must be specified in code as the attribute's parameter. However, in certain scenarios, the property may be required to have a configurable persistent alias, and it must be possible to configure it in a deployed application by an administrator. In this instance, the CalculatedPersistentAliasAttribute attribute should be used.

可通过 PersistentAlias 属性实现在数据库级别上执行筛选和排序的非持化的计算属性

PersistentAlias 属性采用一个参数来指定用于计算数据库服务器端属性值的表达式。

必须在代码中将持久性别名指定为属性的参数。

但是, 在某些情况下, 该属性可能需要具有可配置的持久别名, 并且必须可以在部署的应用程序中由管理员对其进行配置。

在此实例中, 应使用 CalculatedPersistentAliasAttribute 属性。

The CalculatedPersistentAliasAttribute contains two properties initialized via the attribute's constructor. The first parameter specifies the property name for which you would like to set up a persistent alias. The second parameter specifies the property which returns the alias' expression. The property which returns the alias' expression can return different expressions based on a specific rule. For example, you can implement logic which loads the alias expression from a configuration file which can be customized by a system administrator.

Note that the CalculatedPersistentAliasAttribute attribute is initialized at the application startup, while the application is being set up. So, if you want to change the value returned by the property which specifies the alias expression, this should be done while the application is being initialized, for example, in a module's constructor.

The following code snippet illustrates use of the CalculatedPersistentAliasAttribute. The Product class contains the calculated ProductName property, which has a configurable persistent alias:

CalculatedPersistentAliasAttribute 构造函数中有两个参数。
第一个参数指定要为其设置永久别名的属性名。
第二个参数指定返回别名 "表达式" 的属性。
返回别名 "表达式" 的属性可以根据特定规则返回不同的表达式。例如, 您可以实现从配置文件中加载别名表达式的逻辑, 系统管理员可以自定义它。
请注意, 在应用程序初始化时, CalculatedPersistentAliasAttribute 属性在应用程序启动时初始化。因此, 如果要更改指定别名表达式的属性返回的值, 则应在初始化应用程序时 (例如在模块的构造函数中) 执行此操作。
下面的代码段说明了 CalculatedPersistentAliasAttribute 的使用。该产品类包含计算的产品属性, 它具有可配置的持久别名:
Show Me

The complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E1771.

[CalculatedPersistentAlias("ProductName", "ProductNameAlias"), DefaultClassOptions]
//ProductName 这个属性的值将来从ProductNameAlias中取得公式内容.
public class Product : BaseObject {
public Product(Session session) : base(session) { } private static string productNameFormat = "{Manufacturer} {Model}";
private static string productNameAlias = "concat(Manufacturer, Model)"; public string ProductName {
get { return ObjectFormatter.Format(
productNameFormat, this, EmptyEntriesMode.RemoveDelimiterWhenEntryIsEmpty ); }
}
[Browsable(false)]
public static string ProductNameAlias {
get { return productNameAlias; }
}
public static void SetProductNameFormat(string productNameFormat, string productNameAlias) {
if(!string.IsNullOrEmpty(productNameFormat)) {
Product.productNameFormat = productNameFormat;
}
if(!string.IsNullOrEmpty(productNameAlias)) {
Product.productNameAlias = productNameAlias;
}
} public string Manufacturer {
get { return GetPropertyValue<string>("Manufacturer"); }
set { SetPropertyValue<string>("Manufacturer", value); }
}
public string Model {
get { return GetPropertyValue<string>("Model"); }
set { SetPropertyValue<string>("Model", value); }
}
public string Revision {
get { return GetPropertyValue<string>("Revision"); }
set { SetPropertyValue<string>("Revision", value); }
}
}

The persistent alias' value is initialized from the application's configuration file in a module's constructor:

Note that a property which returns the persistent alias' expression must be declared as public and static (Public and Shared in VB).

在模块的构造函数中, 从应用程序的配置文件中初始化持久性别名 "值:

请注意, 返回持久性别名" 表达式的属性必须声明为公共和静态 (在 vb 中为公共和共享)。

public sealed partial class CalculatedAliasModule : ModuleBase {
public CalculatedAliasModule() {
InitializeComponent(); Product.SetProductNameFormat(
ConfigurationManager.AppSettings["ProductNameFormat"],
ConfigurationManager.AppSettings["ProductNameAlias"]
);
}
}
此外, 还需要以下列方式重写 ModuleBase. CustomizeTypesInfo 方法:
using DevExpress.ExpressApp.Xpo;
// ...
public override void CustomizeTypesInfo(ITypesInfo typesInfo) {
base.CustomizeTypesInfo(typesInfo);
CalculatedPersistentAliasHelper.CustomizeTypesInfo(typesInfo);
}

Note that two business classes from the Business Class Library use the CalculatedPersistentAliasAttribute attribute. The Person class uses this attribute to configure the format of the calculated FullName property, and theAddress class uses this attribute to configure the calculated FullAddress property. To learn how to configure the format of these properties, refer to the How to: Change the Format Used for the FullAddress and FullName Properties topic.

请注意, 业务类库中的两个业务类使用 CalculatedPersistentAliasAttribute 属性。"人员" 类使用此特性来配置计算的 fullname 属性的格式, 而地址类使用此特性来配置计算的 FullAddress 属性。

要了解如何配置这些属性的格式,请参阅如何: 更改用于 FullAddress 和 fullname 属性主题的格式。

PersistentAliasAttribute & CalculatedAttribute & CalculatedPersistentAliasAttribute的更多相关文章

  1. XAF应用开发教程-内置Attribute功能列表

    在 XAF 框架,一些用来生成一个业务应用程序的信息是在Attribute中指定.您可以将属性应用到业务类 (或它的成员) 指定验证规则,指定如何对数据进行显示. 设置关系类等.本主题提供了有关在何处 ...

  2. XAF-列表视图数据访问模式

    本主题介绍有关列表视图如何提供数据访问的几种方式.请注意,选择正确的方式对于实现XAF应用程序的最佳性能至关重要.    数据访问模式概述   在模型编辑器中,通过 视图-> <ListV ...

  3. Make a Property Calculable 使属性可计算

    In this lesson, you will learn how to manage calculated properties. For this purpose, the Payment cl ...

  4. How to: Calculate a Property Value Based on Values from a Detail Collection 如何:基于详细信息集合中的值计算属性值

    This topic describes how to implement a business class, so that one of its properties is calculated ...

随机推荐

  1. Mosquitto安装调试实录

    1. 安装 以Centos 7.x为例,先安装依赖项(笔者使用阿里云资源,部分依赖项可能未列出): yum install gcc-c++ yum install openssl-devel yum ...

  2. Docker 命令总结

    1 启动镜像 docker run -i -t centos /bin/bash

  3. My Heart Will Go On(我心永恒)

    My Heart Will Go On(我心永恒) 歌词(英文) 歌词(中文) 简介:电影<泰坦尼克号>插曲   歌手:Celine Dion(席琳·迪翁)   词作:韦尔·杰宁斯(Wil ...

  4. php分享一个n维数组转一维的函数

    好玩,所以做了这么一个函数,来输出唐诗 函数如下 function changearr($arr){ if(count($arr)==count($arr,1)){ return $arr; } el ...

  5. 1088. [SCOI2005]扫雷Mine【网格DP】

    Description 相信大家都玩过扫雷的游戏.那是在一个n*m的矩阵里面有一些雷,要你根据一些信息找出雷来.万圣节到了 ,“余”人国流行起了一种简单的扫雷游戏,这个游戏规则和扫雷一样,如果某个格子 ...

  6. 「GXOI / GZOI2019」旅行者

    题目 我还是太傻了 考虑每一条边的贡献,对于一条有向边\((u,v,w)\),我们求出\(k\)个关键点中到\(u\)最近的距离\(dis_1\),以及\(v\)到\(k\)个关键点中最近的距离\(d ...

  7. 【bzoj2693】jzptab 莫比乌斯反演+线性筛

    题目描述 输入 一个正整数T表示数据组数 接下来T行 每行两个正整数 表示N.M 输出 T行 每行一个整数 表示第i组数据的结果 样例输入 1 4 5 样例输出 122 题解 莫比乌斯反演+线性筛 由 ...

  8. 20165302 敏捷开发与XP实践作业

    20165302 敏捷开发与XP实践实验报告 一.提交点一 1.实验要求 参考 http://www.cnblogs.com/rocedu/p/6371315.html#SECCODESTANDARD ...

  9. ajax和原生ajax、文件的上传

    ajax理解: ajax发送的请求是异步处理的.也就是说如下形式: function f1(){ $.ajax( { ....... success:function(){ a= return a } ...

  10. 论文笔记 M. Saquib Sarfraz_Pose-Sensitive Embedding_re-ranking_2018_CVPR

    1. 摘要 作者使用一个pose-sensitive-embddding,把姿态的粗糙.精细信息结合在一起应用到模型中. 用一个新的re-ranking方法,不需要重新计算新的ranking列表,是一 ...