0

I have a class which inherits Role class.

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

As Role inherits RoleBase and last class has Name property, how could I define this unique rule on Name?

Later update:

this is the solution I've succeeded to implement, edit the Designed.Diffs(through model designer)

 <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>
Alexa Adrian
  • 1,778
  • 2
  • 23
  • 38

2 Answers2

0

First of all I think that you should hide the inherited property if you want to add some constraints just on this one

private string name;
        public static string PropertyName = "Name";
       new public string Name
        {
            get { return Name; }
            set { Name = value; }
        }
Paweł Swajdo
  • 391
  • 1
  • 13
0

You can use RuleCombinationOfPropertiesIsUnique which is a class attribute rather than a property attribute.

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

Or for anything more complex, you have the RuleFromBoolProperty attribute. See the documentation here.

E.g.,

[RuleFromBoolProperty("RoleUniqueName", DefaultContexts.Save, 
  "Role with this Name already exists", UsedProperties = "Name")]
public bool IsNameUnique {
      //... 
}
shamp00
  • 11,106
  • 4
  • 38
  • 81