Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8655015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:55:43+00:00 2026-06-12T14:55:43+00:00

Validation on property of child class does not work when I have 2 different

  • 0

Validation on property of child class does not work when I have 2 different rulesets for The parent and child.

This is the class code: Mytype is the parent and Person is the child

    [HasSelfValidation]
    public class MyType
    {
        [SelfValidation(Ruleset = "RulesetA")]
        [SelfValidation(Ruleset = "RulesetB")]
        public void DoValidate(ValidationResults results)
        {
        }

        [NotNullValidator(Ruleset = "RulesetA")]
        [ObjectValidator("RulesetA", Ruleset = "RulesetA")]
        public Person Person { get; set; }

    }

    public class Person
    {
        [NotNullValidator(Ruleset = "RulesetB")]
        public string GivenName { get; set; }

    }

This is the custom validator class to validate MyType class against all rulesets:

    public interface IValidator<T>
    {
        ValidationResults Validate(T target);
    }

    public class MyValidator : IValidator<MyType>
    {
        public ValidationResults Validate(MyType target)
        {
            return Validation.Validate(target, new string[] {"RulesetA", "RulesetB"});
        }
    }

And this is the test which fails: (IsValid should be set to False but it’s True)

    [TestMethod]
    public void Should_return_false_when_validating_MyType_without_PersonApplying_GivenName()
    {
        //arrange
        var myType = new MyType()
                            {
                                Person= new Person()
                            };
        myType.Person.GivenName = null;

        //act
        MyValidator _validator = new MyValidator();
        var resultList = _validator.Validate(myType);

        //assert
        Assert.IsFalse(resultList.IsValid);
    }

Would you please help?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T14:55:44+00:00Added an answer on June 12, 2026 at 2:55 pm

    VAB validates your object per ruleset and concatenates the validation results. This is what the Validation.Validate method looks like:

    var resultsReturned = new ValidationResults();
    
    foreach (string ruleset in rulesets)
    {
        var validator = ValidationFactory.CreateValidator(
            targetType, ruleset, source);
    
        foreach (var validationResult in validator.Validate(target))
        {
            resultsReturned.AddResult(validationResult);
        }
    }
    
    return resultsReturned;
    

    In other words, a validation on an object is always performed on a single ruleset. Since the ObjectValidator is only decorated for RulesetA, the Person object will not get validated when running on RulesetB.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Ef 4 code first and have a parent table with a child
I have this model class User include DataMapper::Resource include BCrypt property :id, Serial property
Does JPA contains any validation API? E.g. email property validation like this in hibernate
I have the following class used for custom validation: [AttributeUsage(AttributeTargets.Property, AllowMultiple=false, Inherited=true)] public sealed
I'm using the Validation Application Block from Microsoft. I have a string property which
I'm trying to perform a validation property. We have a nullable property called: public
I'm trying to perform a validation property. We have a nullable property called: public
i need associate a entity property Address in my Person class entity with expressions
I have a Decorator Control class which I want to collect all the validation
I have a ViewModel class that implements the IDataErrorInfo Interface . In each property's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.