Skip to main content
A newer version of this page is available. .

Criteria Properties in XPO

  • 2 minutes to read

The example below illustrates how to implement Criteria Properties in an XPO persistent class.

private string dataTypeName;
[Browsable(false)]
public string DataTypeName {
    get { return dataTypeName; }
    set {
        Type type = XafTypesInfo.Instance.FindTypeInfo(value) == null ? null :
            XafTypesInfo.Instance.FindTypeInfo(value).Type;
        if(dataType != type) {
            dataType = type;
        }
        if(!IsLoading && value != dataTypeName) {
            Criteria = String.Empty;
            CriteriaInPopupWindow = String.Empty;
        }
        SetPropertyValue<string>("DataTypeName", ref dataTypeName, value);
    }
}

private Type dataType;
[TypeConverter(typeof(LocalizedClassInfoTypeConverter))]
[ImmediatePostData, NonPersistent]
public Type DataType {
    get { return dataType; }
    set {
        if(dataType != value) {
            dataType = value;
            DataTypeName = (value == null) ? null : value.FullName;
        }
    }
}

private string criteria;
[CriteriaOptions("DataType")]
[Size(SizeAttribute.Unlimited), ObjectValidatorIgnoreIssue(typeof(ObjectValidatorLargeNonDelayedMember))]
[ModelDefault("RowCount", "0")]
[VisibleInListView(true)]
[EditorAlias(EditorAliases.CriteriaPropertyEditor)]
public string Criteria {
    get { return criteria; }
    set { SetPropertyValue<string>("Criteria", ref criteria, value); }
}

private string criteriaInPopupWindow;
[CriteriaOptions("DataType")]
[Size(SizeAttribute.Unlimited), ObjectValidatorIgnoreIssue(typeof(ObjectValidatorLargeNonDelayedMember))]
[ModelDefault("RowCount", "0")]
[VisibleInListView(true)]
[EditorAlias(EditorAliases.PopupCriteriaPropertyEditor)]
public string CriteriaInPopupWindow {
    get { return criteriaInPopupWindow; }
    set { SetPropertyValue<string>("CriteriaInPopupWindow", ref criteriaInPopupWindow, value); }
}

See the CriteriaOptionsAttribute attribute description for details on using this attribute.