【问题标题】:How to add unique constraint on a property inherited from Role class in DevExpres, Xpo?如何对从 DevExpress、Xpo 中的 Role 类继承的属性添加唯一约束?
【发布时间】:2017-01-19 07:18:38
【问题描述】:

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

【问题讨论】:

    标签: c# devexpress xpo


    【解决方案1】:

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

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

    【讨论】:

    • 我从来没有尝试过这种方式......最后我所做的是添加来自编辑我设计的.diffs文件的设计师的独特约束。
    • “查看更新的问题” - 对于我正在谈论的解决方案
    【解决方案2】:

    您可以使用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 {
          //... 
    }
    

    【讨论】:

      猜你喜欢
      • 2011-04-25
      • 1970-01-01
      • 1970-01-01
      • 2015-08-04
      • 1970-01-01
      • 1970-01-01
      • 2014-07-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多