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

  • Home
  • SEARCH
  • 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 3353226
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:07:32+00:00 2026-05-18T02:07:32+00:00

I am developing a WPF Application using MVVM Architecture. I am an amateur in

  • 0

I am developing a WPF Application using MVVM Architecture. I am an amateur in WPF so bear with me..

I have two model classes. Parent class has an object of another (child) class as its property. (i mean nested objects and not inherited objects)

For instance, consider the following scenario.

public class Company
{

   public string CompanyName {get; set;}

   public Employee EmployeeObj {get; set;}
}

public class Employee 
{

   public string FirstName {get; set;}

   public string LastName {get; set;}

}    

I want to validate the properties of Employee entity using Enterprise Library Validation Block.

I was able to do it by implementing IDataErroInfo interface in employee class as shown below

public class Employee :  IDataErrorInfo

{

   [NotNullValidator(MessageTemplate="First Name is mandatory"]
   public string FirstName {get; set;}

   [StringLengthValidator(0,20,MessageTemplate="Invalid")]
   public string LastName {get; set;}

   public string Error
   {
        get
        {
            StringBuilder error = new StringBuilder();

            ValidationResults results = Validation.ValidateFromAttributes<Employee>(this);

            foreach (ValidationResult result in results)
            {
                error.AppendLine(result.Message);
            }

            return error.ToString();
        }

    }

    public string this[string propertyName]
    {
        get
        {
            ValidationResults results = Validation.ValidateFromAttributes<Employee>(this);

            foreach (ValidationResult result in results)
            {
                if (result.Key == propertyName)
                {
                    return result.Message;
                }
            }

            return string.Empty;
        }
    }
}

I dont want to implement IDataErroInfo for every child model i create.

Is there any way to validate the Employee object by implementing IDataErrorInfo on the parent (Company) class ?

And also is there any triggers to start validation of objects. I would like to validate the objects only when i want to and not all the time.

  • 1 1 Answer
  • 1 View
  • 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-05-18T02:07:33+00:00Added an answer on May 18, 2026 at 2:07 am

    You can absolutely implement IDataErrorInfo on a base class using Validation Application Block. Here is an article that describes how to. The code basically comes down to this:

    public abstract class DataErrorInfo : IDataErrorInfo
    {
        string IDataErrorInfo.Error
        {
            get { return string.Empty; }
        }
    
        string IDataErrorInfo.this[string columnName]
        {
            get
            {
                var prop = this.GetType().GetProperty(columnName);
                return this.GetErrorInfo(prop); 
            }
        }
    
        private string GetErrorInfo(PropertyInfo prop)
        {
            var validator = this.GetPropertyValidator(prop);
    
            if (validator != null)
            {
               var results = validator.Validate(this);
    
               if (!results.IsValid)
               {
                  return string.Join(" ",
                      results.Select(r => r.Message).ToArray());
               }
            }
    
            return string.Empty;
        }
    
        private Validator GetPropertyValidator(PropertyInfo prop)
        {
            string ruleset = string.Empty;
            var source = ValidationSpecificationSource.All;
            var builder = new ReflectionMemberValueAccessBuilder();
            return PropertyValidationFactory.GetPropertyValidator(
                this.GetType(), prop, ruleset, source, builder);
        }
    }
    

    You can use this abstract class add validation behavior to your entities by inheriting from it:

    public partial class Customer : DataErrorInfo
    {
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application which I am developing using WPF\Prism\MVVM. All is going well
I am developing an application in WPF using the MVVM pattern. If I have
I'm developing a WPF application using MVVM. Inside a Window, I have a control
I am developing an application using WPF/MVVM. I have a WCF data service project
I am developing a WPF application (using MVVM) and have implemented IDataErrorInfo on my
I'm developing a .NET 4.0 application using PRISM and MVVM, as well as WPF.
I'm developing WPF applications using MVVM pattern. I have ViewModel with code like this:
I'm in the early phases of developing a WPF application (using the MVVM pattern)
I'm developing a WPF application using the MVVM pattern and I need to display
I'm developing a WPF/PRISM based application. The parent view(usercontrol) has many regions in it

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.