Criterion class

Houses a group of Criteria, and properties on how the Criterion relates to other Criterion. Is passed to the ObjectFactory, and is used to generate SQL where clauses.

Namespace: ReFlex.Data namespace
Assembly: ReFlex.Data.dll

Syntax

public class Criterion<DefaultObjectType> : ICriterion

Constructors

Criterion(CriteriaOperatorEnum globalCriteriaOperator);

Remarks

The Criterion object provides a powerful, compiler supported means to build query clauses to be passed to ObjectFactory. Ultimately, ObjectFactory uses these Criterion to build SQL where clauses when retrieving data from the database.

ObjectFactory's methods provide facilities to pass multiple Criterion.

The Criterion.GlobalCriteriaOperator defines how the group of Criteria are compared with any other Criterion passed to the ObjectFactory method.

DefaultObjectType only defines the default object type for Criterion to assume you are referring to when calling the Add method and only passing a string for field. If you pass an IField object instead, whatever type(s) defined for the IField will be used. For example you could also pass an Field<DifferentObjectType>() in the Add method.

If passing Criterion that refer to a different type than the subject, you must ensure that you have also passed the appropriate Relationship objects to ensure that the fields will be available for evaluation.

Examples

Relationship pageRelationship = new Relationship(typeof(Page), typeof(ControlContent), RelationshipTypeEnum.StrongParent);

Criterion<ControlContent> controlContentCriterion = new Criterion<ControlContent>(CriteriaOperatorEnum.And)
    .Add("IsConstant", true, ComparisonOperatorEnum.Equals, CriteriaOperatorEnum.And)
    .Add("Status", ControlContent.StatusEnum.Current, ComparisonOperatorEnum.Equals, CriteriaOperatorEnum.And));
Criterion<Page> pageCriterion = new Criterion<Page>(CriteriaOperatorEnum.And)
    .Add("IsHidden", true, ComparisonOperatorEnum.Equals, CriteriaOperatorEnum.And));

List<ControlContent> controlContent;
using (ObjectFactory<ControlContent> mapper = new ObjectFactory<ControlContent>())
    controlContent = mapper.GetDataObjects(new ICriterion[] { controlContentCriterion, pageCriterion }
    , new Ordering().Add<ControlContent>("ControlContentID", Direction.Ascending)
    , new Relationship[] { pageRelationship });