Workaround to ErrorProvider not support Nested BO

As Andy suggested, the work around to ErrorProvider not support Nested BO is fairly simple: expose the child property at parent, then add special deep look up code in IErrorProvider implementation.

Here is my example, the Name property is nested in StakeholderNameBO.LastName:

        private static PropertyInfo<string> NameProperty = RegisterProperty<string>(typeof(OrganizationBO), new PropertyInfo<string>("Name"));
        public string Name
        {
            get { return StakeholderNameBO.LastName; }
            set { StakeholderNameBO.LastName = value; }
        }

 string IDataErrorInfo.this[string columnName]
        {
            get
            {
                string result = string.Empty;
                if (!IsValid)
                {
                    if (columnName == "Name")
                    {
                        // Special process for nested BO property
                        if (this.StakeholderNameBO != null)
                        {
                            var rule = this.StakeholderNameBO.BrokenRulesCollection
                                .GetFirstBrokenRule("LastName");

                            if (rule != null) result = rule.Description;                           
                        }
                    }else
                    {
                        // The original code in base class only do on level look up.
                        var rule = ValidationRules.GetBrokenRules().GetFirstBrokenRule(columnName);
                        if (rule != null) result = rule.Description;
                    }
                }
                return result;
            }
        }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s