Validation 验证集合属性的子级

Validation 验证集合属性的子级,validation,spring.net,Validation,Spring.net,我继承了一个应用程序,它在包括验证在内的所有方面都大量使用Spring.NET。现在,我正试图弄清楚如何验证集合属性的子级,因此给定如下结构: public class ParentObj { public virtual ICollection<ChildObj> Children { get; set; } } public class ChildObj { public virtual string SomeField { get; set; } } 编辑1

我继承了一个应用程序,它在包括验证在内的所有方面都大量使用Spring.NET。现在,我正试图弄清楚如何验证集合属性的子级,因此给定如下结构:

public class ParentObj
{
    public virtual ICollection<ChildObj> Children { get; set; }
}

public class ChildObj
{
    public virtual string SomeField { get; set; }
}
编辑1 好的,我现在有了进展(),并将我的配置修改为:

<v:group id="ParentObjValidator">
    <v:collection context="Children" when="Children != null and Children.Count > 0">
        <v:ref name="ChildObjValidator" />
        <!-- message part -->
    </v:collection>
</v:group>

<v:group id="ChildObjValidator">
    <v:condition test="SomeField.Length <= 100" when="!string.IsNullOrEmpty(SomeField)">
        <!-- message part -->
    </v:condition>
</v:group>


现在它似乎很高兴。。。然而,我预期的失败没有被发现,所以我不确定孩子们是否真的被验证了(或者我的规则是错误的)。

明白了!我缺少集合类型的
include element errors=“true”
属性:

<v:group id="ParentObjValidator">
     <v:collection context="Children" when="Children != null and Children.Count > 0" include-element-errors="true">
        <v:ref name="ChildObjValidator" />
        <!-- message part -->
    </v:collection>
</v:group>

<v:group id="ChildObjValidator">
    <v:condition test="SomeField.Length <= 100" when="!string.IsNullOrEmpty(SomeField)">
        <!-- message part -->
    </v:condition>
</v:group>

现在似乎已经开始运行了

<v:group id="ParentObjValidator">
     <v:collection context="Children" when="Children != null and Children.Count > 0" include-element-errors="true">
        <v:ref name="ChildObjValidator" />
        <!-- message part -->
    </v:collection>
</v:group>

<v:group id="ChildObjValidator">
    <v:condition test="SomeField.Length <= 100" when="!string.IsNullOrEmpty(SomeField)">
        <!-- message part -->
    </v:condition>
</v:group>