如何在DevExpres,Xpo中从Role类继承的属性上添加唯一约束?

时间:2017-01-19 07:18:39

标签: c# devexpress xpo

我有一个继承Role类的类。

 public class WMSRole : Role
{
    //....some properties/relationships
}

由于Role继承了RoleBase,而最后一个类具有Name属性,我如何在Name上定义这个唯一规则?

稍后更新:

这是我成功实施,编辑Designed.Diffs(通过模型设计师)的解决方案

 <Validation>
    <Rules>
      <RuleUniqueValue Id="WmsRole Name Should be Unique" TargetContextIDs="Save" TargetCollectionOwnerType="" TargetCollectionPropertyName="" TargetPropertyName="Name" TargetType="Davanti.WMS.Core.Model.Authorisation.WMSRole" IsNewNode="True" />
      <RuleRequiredField Id="WmsRole Name is Required" TargetContextIDs="Save" TargetCollectionOwnerType="" TargetCollectionPropertyName="" TargetPropertyName="Name" TargetType="Davanti.WMS.Core.Model.Authorisation.WMSRole" IsNewNode="True" />
    </Rules>
  </Validation>

2 个答案:

答案 0 :(得分:0)

首先,我认为如果你想在这个上添加一些约束,你应该隐藏继承的属性

private string name;
        public static string PropertyName = "Name";
       new public string Name
        {
            get { return Name; }
            set { Name = value; }
        }

答案 1 :(得分:0)

您可以使用RuleCombinationOfPropertiesIsUnique这是一个类属性而不是属性属性。

[RuleCombinationOfPropertiesIsUnique("RoleUniqueName", DefaultContexts.Save, "Name")]
public class MyRole : Role {   
    public MyRole(Session session) : base(session) { }
    // etc...   
}

或者对于任何更复杂的内容,您都拥有RuleFromBoolProperty属性。请参阅文档here

如,

[RuleFromBoolProperty("RoleUniqueName", DefaultContexts.Save, 
  "Role with this Name already exists", UsedProperties = "Name")]
public bool IsNameUnique {
      //... 
}