Original: XPO learning three - condition object
XPO conditions related classes.
The conditional object of XPO is used to generate data filter conditions, actually the object representation method of SQL statement condition syntax (combination of conditions).
First, mainly related classes:
1. Inherited the class series of abstract class criteriaoperator.
Subclasses inherited in criteriaoperator:
Betweenoperator
Conditional expression of the range, such as: 1000 <= Total Price <= 2000
Binaryoperator
Binary expressions, the most basic expressions, such as: TotalPrice> 100
ContaInperator
Contains expressions, such as exists
Groupopopertor
Combined expressions, using it for repeated nested combinations, it can form any complicated condition tree.
Inoperator
In a list of values, it can be considered to be in SQL.
NOTOPERATOR
Reverse expressions, corresponding to NOT in SQL
Nulloperator
Take a null expression, corresponding to Isnull in SQL
2. Assist CriteriaOperator series.
Subclasses inherited from abstract CriteriaoPerand:
AggRegateOperand
The aggregation operation can be used at this time (provided in an enumerated manner), similar to GroupBY plus HAVING
OperandProperty
Reference class members (PROPPERSISTEN "or field (field) or field (field). The corresponding is the table field.
OperandValue
Value in the expression
OperandValuebase
OperandValue's base class.
Second, detailed description:
(A), conditional object series:
Criteriaoperator
Conditional computation class is an abstract base class for all conditional objects. There is no specific method, just add the attribute Serializable in the class. (It seems that DEV wants to make you manipotype in a serialization method).
Betweenoperator
Range operation class: used to represent a conditional expression of a certain range.
Constructor:
Public Betweenoperator (CriteriaOperand LEFTOPERTY, CRITERIAOPERAND RIGHTOPERAND)
Public Betweenoperator (String Property, CriteriaOperand LEFTOERAND, CRITERIAOPERAND RIGHTOPERAND): This
For example: 1000 <= Total Price <= 2000 Write into NEW BETWEENOPERATOR ("TotalPrice", 1000, 2000))
Binaryoperator
Binary operation objects, that is, a binary arithmetic expression.
Constructor:
Public BinaryOperator (CriteriaOperand Opright, BinaryOperatortype Type)
Public Binaryoperator (String PropertyName, Object Value, BinaryOperatorType Type): this
The type of TYPE is binaryOperatortype is a binary operator enumeration, and you know what it means.
BinaryOperatortype {Equal, Greater, Greaterorequal, Less, Lessorequal, Like, Notequal}
For example: TotalPrice> 100 is written: New Binaryoperator ("TotalPrice", 10, binaryoperatortype.greater)
ContaInperator
Contains expression:
This original document is: useed in a search criteria to Filter Collection Contents.
Everyone knows between the two solid classes, one-to-many or more, one of the references to another class is implemented through the XPCollection type. Filter for this type of properties or fields must use ContaInPerator
Constructor:
Public ContainSoperator (OperandProperty ObjectProperty, criteriaoperator operand)
Public ContainSoperator (String Property, Criteriaoperator Operand): This (New Operandproperty (property), Operand
For example, two classes:
Public Class Customer: XPOBJECT
{
///
/// There are multiple orders, which are aggregated relationships.
/// summary>
[Association ("CustomerORDERS", Typeof (Order), aggregated]
Public XPCOLLECTION ORDERS
{
Get {return getcollection;}
}
}
///
/// Order
/// summary>
Public Class Order: XPObject
{
///
/// The user of the order
/// summary>
[Association ("CustomerRorders")]]]]]
Public Customer Customer;
///
/// order amount
/// summary>
Public Decimal FREIGHT;
}
This connection is a pair of relationships, I want to query the user of the order equal to 1000.
XpCollection Collection = New XpCollection (TypeOf (Customer),
New ContainSoperator ("ORDERS", New Binaryoperator ("FREIGHT", 1000, BinaryOperatortype.equal);
It is actually used in combination of two conditional objects.
Groupopopertor
Combined expressions, very powerful, using it for repeated nested combinations, can form any complicated condition tree.
You can combine any classes of the CriteriaOperator class series, including itself.
Constructor: public groupopopertor (criteriaoperator [] Operands);
Operands are grouped by the groupoperatortype.and type.
Public Groupoperatorator (GroupoperAtortype Type, criteriaoperator [] Operands);
For example: there are such four classes, users, roles, addresses, orders
The relationship between them except that users and orders are one-to-many, and others are much more.
///
/// User
/// summary>
Public Class Customer: XPOBJECT
{
Public String Name = ""
Public String CompanyName = ""
Public String Phone = "";
Public String Fax = ""
[ValueConvertR (TypeOf (CodeConvertor)]]]]
Public String Sex = "2";
///
/// There are multiple orders, which are aggregated relationships.
/// summary>
[Association ("CustomerORDERS", Typeof (Order), aggregated]
Public XPCOLLECTION ORDERS
{
Get {return getcollection;}
}
///
/// A user can have multiple addresses
/// summary>
[Association ("CustomeraDresses", TypeOf (Address)]]
Public XPCOLLECTION Addresses
{
Get {Return getCollection ("Addresses");
}
///
/// Role, one user can be in multiple characters.
/// summary>
[Association ("CustomersGroups", TypeOf (Group)]
Public XPCOLLECTION GROUPS
{
Get {return getCollection ("groups");
}
Public Customer ()
{
}
Public Customer (String NewcompanyName, String Newphone, String Newfax)
{
Name = newname;
CompanyName = newcompanyname;
Phone = newphone;
Fax = newfax;
}
}
///
/// address
/// summary>
Public Class Address: XPOBJECT
{
Public String Street = ""
///
/// An address may have multiple users.
/// summary>
[Association ("CustomeraDresses")]]]
Public Customer Customer;
Public address ()
{
}
Public Address (String theest) {
Street = this.
}
}
///
/// Order
/// summary>
Public Class Order: XPObject
{
Public DateTime OrderDate;
Public DateTime RequiredDate;
Public DateTime shippedddate;
Public int shipvia;
///
/// order amount
/// summary>
Public Decimal FREIGHT;
///
/// The user of the order
/// summary>
[Association ("CustomerRorders")]]]]]
Public Customer Customer;
Public order ()
{
}
Public Order (DateTime NewRequiredDate, DateTime NewshippedDate, Int Newshipvia, Decimal NewFreight)
{
ORDERDATE = NewOrDerdate;
RequiredDate = newRequiredDate;
ShippedDate = newshippeddate;
Shipvia = newshipvia;
FREIGHT = NewFreight;
}
}
///
/// Character
/// summary>
Public Class Group: XPObject
{
Public String Name = ""
///
/// A user owned by a role
/// summary>
[Association ("CustomersGroups", Typeof (Customer)]]
Public XPCollection Customers
{
Get {Return getCollection ("Customers");
}
Public group ()
{
}
Public group (String newname)
{
Name = newname;
}
}
Find (role is Administrator and the order amount is greater than 20) or home address in Tianjin user's conditional object:
New Groupoperator
(
Groupoperatortype.or,
New ContainSoperator ("Addresses", New BinaryOperator ("Street", "Tianjin", binaryOperatortype.equal),
New Groupoperator
(
Groupoperatortype.and,
New ContainSoperator ("Groups", New Binaryoperator ("Name", "Administrator", BinaryOperatorType.equal),
New ContainSoperator ("Orders", New Binaryoperator ("FREIGHT", 20, BinaryOperatorType.greaterorequal)
)
)
Inoperator
Composition of an expression similar to the SQL expression:
Constructor: public inoperator (criteriaOperand [] Operands);
Public Inoperator (String propertyName);
Very simple, no exemplification
NOTOPERATOR
Similar to NOT operations in SQL.
Constructor:
Public NOTOPERATOR (CriteriaOperator Operand);
For example: New Nulloperator ("Company")
Nulloperator
Take an empty value.
Constructor
Public nulloperator (String PropertyName);
Public Nulloperator (OperandProperty Operand);
For example: New NullOperator (New Nulloperator ("Company"))
(B) Operator series of conditions:
CriteriaOperand
The operator of the condition object, contains the number of arithmeters, operators, operations, and the like, is an abstract class.
AggRegateOperand
The aggregation operation can be used at this time (provided in an enumerated manner), similar to GroupBY plus HAVING.
Constructor :
Public AggRegateOperand (OperandProperty ObjectProperty, Operandproperty AggregateProperty, Aggregate Type, Criteriaoperator criteria);
Still those classes, people who want to find the total amount of orders less than 100
new XPCollection (typeof (Customor), new BinaryOperator (new AggregateOperand (new OperandProperty ( "Orders"), new OperandProperty ( "Freight"), Aggregate.Sum, null), new OperandValue (100), BinaryOperatorType.Less))
It can be seen that the use of aggregate function type enumeration
Public Enum aggregate {avg, count, max, min, none}
Or address is similar to Shanghai, and this address is unique:
New XpCollection (TypeOf (Cutomor), New BinaryOperator (New AggregateOperand ("Addresses",
New Binaryoperator ("Street", "Shanghai%", BinaryOperatortype.like), New OperandValue (1), BinaryOperatortype.equal)
OperandProperty
Reference class members (PROPPERSISTEN "or field (field) or field (field). The corresponding is the table field.
Constructor:
Public OperandProperty (String PropertyName);
The example is above, pay attention to the non-persistent class member is not directly used.
OperandValue
The value in the expression.
Constructor:
Public OperandValue; Object Value;
Nothing is saying.
OperandValueBaseOperandValue base class. Basically useless.