开发者论坛

 找回密码
 注册 (请使用非IE浏览器)
查看: 14166|回复: 0

XPO 条件相关类

[复制链接]

0

精华

379

贡献

793

赞扬

帖子
367
软币
7240
在线时间
785 小时
注册时间
2013-6-8
发表于 2016-5-8 12:02:01 | 显示全部楼层 |阅读模式
XPO的条件对象用来生成数据筛选条件,实际就是SQL语句条件语法树(条件表达式的组合)的对象表示方法。
一、主要相关类:
1、继承于抽象类CriteriaOperator的类系列。
继承于CriteriaOperator的子类有:
       BetweenOperator
              取范围的条件表达式类,如:1000 <= Total Price <= 2000
    BinaryOperator
              二元表达式类,最基本的表达式,比如:TotalPrice>100
    ContainsOperator
              包含表达式类,比如:exists
    GroupOperator
              组合表达式类,利用它进行反复嵌套组合,可以组成任意复杂的条件树。
    InOperator
              在某个值列表范围内的表达式,可以认为是SQL中的in
    NotOperator
              取反表达式,对应SQL中的not
    NullOperator
              取空值表达式,对应SQL中的 IsNull
2、辅助CriteriaOperator的CriteriaOperand类系列。
       继承于抽象类CriteriaOperand的子类有:
        AggregateOperand
              聚合操作,可以在此时使用各种聚合函数(以枚举方式提供),类似于groupby 再加Having
      OperandProperty
              表达式中的引用类成员(实体类(XPPersistent)的可持久化的属性(property)或字段(field))。对应的就是表字段。
        OperandValue
              表达式中的值
      OperandValueBase
              OperandValue的基类。
二、详细描述:
(A)、条件对象系列:
CriteriaOperator
                 条件运算类是所有条件对象的抽象基类。没有任何具体方法,只是在类上加了属性Serializable。(看来Dev是想让大家手动以序列化方式持久)。

BetweenOperator
                     范围运算类:用来表示某个值范围的条件表达式。
                     构造函数:
                     public BetweenOperator(CriteriaOperand objectProperty, CriteriaOperand leftOperand, CriteriaOperand rightOperand)
              public BetweenOperator(string property, CriteriaOperand leftOperand, CriteriaOperand rightOperand) : this(new OperandProperty(property), leftOperand, rightOperand)

              比如:1000 <= Total Price <= 2000 写成new BetweenOperator("TotalPrice", 1000, 2000))

      BinaryOperator
                     二元运算对象,也就是一个二元运算表达式。
                     构造函数:
                     public BinaryOperator(CriteriaOperand opLeft, CriteriaOperand opRight, BinaryOperatorType type)
              public BinaryOperator(string propertyName, object value, BinaryOperatorType type) :
              this(new OperandProperty(propertyName), new OperandValue(value), type)
              参数type的类型BinaryOperatorType是二元操作符枚举,看名称就知道意思啦。
                     BinaryOperatorType{ Equal, Greater , GreaterOrEqual , Less , LessOrEqual , Like,NotEqual }
              比如:TotalPrice>100 写成: new BinaryOperator("TotalPrice", 10, BinaryOperatorType.Greater)


ContainsOperator
                     包含表达式:
这个原始文档是:Used in a search criteria to filter collection contents.
                     大家知道两个实体类之间是一对多或多对多时,其中一个对另一个类的引用是通过XPCollection类型实现的。对此类型的属性或字段的筛选就必须使用ContainsOperator
   构造函数:
              public ContainsOperator(OperandProperty objectProperty, CriteriaOperator operand)
public ContainsOperator(string property, CriteriaOperator operand) : this(new OperandProperty(property), operand)
                 比如两个类:
                     public class Customer : XPObject
              {
                   /// <summary>
                  /// 有多个订单,是聚集关系。
                  /// </summary>
                  [Association("CustomerOrders", typeof (Order)), Aggregated]
                  public XPCollection Orders
                  {
                       get { return GetCollection("Orders"); }
                  }
              }

              /// <summary>
              /// 订单
              /// </summary>
              public class Order : XPObject
              {
                   /// <summary>
                  /// 订单的所属用户
                  /// </summary>
                  [Association("CustomerOrders")]
                  public Customer Customer;

                   /// <summary>
                  /// 订单金额
                  /// </summary>
                  public Decimal Freight;
              }
          这连个类是一对多关系,我想查询订单金额等于1000的用户。
      XPCollection collection = new XPCollection(typeof(Customer),       new ContainsOperator("Orders ",new BinaryOperator("Freight ",1000,BinaryOperatorType.Equal));
          实际是两个条件对象的组合使用。

回复

使用道具 举报

Archiver|手机版|小黑屋|开发者网 ( 苏ICP备08004430号-2 )
版权所有:南京韵文教育信息咨询有限公司

GMT+8, 2024-4-18 10:45

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表