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



我有一个继承角色类的类。

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

由于角色继承了角色库,最后一个类具有 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>

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

private string name;
        public static string PropertyName = "Name";
       new public string Name
        {
            get { return Name; }
            set { Name = value; }
        }
您可以使用

类属性而不是属性属性的RuleCombinationOfPropertiesIsUnique

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

或者对于更复杂的内容,您具有 RuleFromBoolProperty 属性。请参阅此处的文档。

例如,

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

最新更新