0

我有一个继承 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>
4

2 回答 2

0

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

private string name;
        public static string PropertyName = "Name";
       new public string Name
        {
            get { return Name; }
            set { Name = value; }
        }
于 2017-01-25T12:15:44.337 回答
0

您可以使用RuleCombinationOfPropertiesIsUniquewhich 是类属性而不是属性属性。

[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 {
      //... 
}
于 2017-02-27T12:35:14.523 回答