C# 如何在从DevExpres、Xpo中的角色类继承的属性上添加唯一约束?

C# 如何在从DevExpres、Xpo中的角色类继承的属性上添加唯一约束?,c#,devexpress,xpo,C#,Devexpress,Xpo,我有一个继承角色类的类 public class WMSRole : Role { //....some properties/relationships } 由于角色继承RoleBase,并且最后一个类具有Name属性,我如何在Name上定义此唯一规则 稍后更新: 这是我成功实现的解决方案,编辑Designed.diff(通过模型设计器) 首先,我认为如果您只想在这个属性上添加一些约束,就应该隐藏继承的属性 private string name; public s

我有一个继承角色类的类

 public class WMSRole : Role
{
    //....some properties/relationships
}
由于角色继承RoleBase,并且最后一个类具有Name属性,我如何在Name上定义此唯一规则

稍后更新:

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


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

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

您可以使用
ruleCombinationofPropertiesUnique
,它是类属性而不是属性属性

[RuleCombinationOfPropertiesIsUnique("RoleUniqueName", DefaultContexts.Save, "Name")]
public class MyRole : Role {   
    public MyRole(Session session) : base(session) { }
    // etc...   
}
或者对于更复杂的内容,您可以使用
RuleFromBoolProperty
属性。请参阅文档

例如:


我从来没有试过那样做。。。最后,我所做的是从编辑我的design.diff文件的designer添加了唯一的约束。“请参阅更新的问题”-以获取我所讨论的解决方案
[RuleCombinationOfPropertiesIsUnique("RoleUniqueName", DefaultContexts.Save, "Name")]
public class MyRole : Role {   
    public MyRole(Session session) : base(session) { }
    // etc...   
}
[RuleFromBoolProperty("RoleUniqueName", DefaultContexts.Save, 
  "Role with this Name already exists", UsedProperties = "Name")]
public bool IsNameUnique {
      //... 
}