CSLA .NET

Vibrant discussion about CSLA .NET and using the framework to build great business applications.

Add Business Rules for Business List Base child property

rated by 0 users
Not Answered This post has 0 verified answers | 3 Replies | 1 Follower

Not Ranked
9 Posts
Marsh posted on Wed, May 16 2012 12:23 AM

Hi,

I Have object graphs with parent-child relationship. There are more than two children objects.

Parent object is BusinessBase object where other child objects are BusinessListBase objects.

Now I want to add validation for child objects that if not a single child objects is not added, Then parent objects should not allow to save.

Can anyone suggest how to add validation on BusinessListBaseProperty so it display error notification and CanSave property is  false?

Thanks in advance.

All Replies

Top 10 Contributor
1,764 Posts

How do you want to show the error to the user?

What type of UI do you use?

In general terms you need to decide on where to attach the broken rule:

  • on the "root" object at object level (Csla have no UI helpers for object level)
  • on the list property in "root" (- in WindowsForms will be shown next to a list/datagridview)
  • on another property in "root" to be placed next to this property in UI

In any case you should trigger the rule in the parent based on ChildChanged event like this

    protected override void OnChildChanged(ChildChangedEventArgs e)
    {
        base.OnChildChanged(e);
        
        // If attached to a property
        PropertyHasChanged(PropertyInfo);
        
        // or if attached at object level (this was introduced in Csla 4.2.0)
        CheckObjectRules();

    }

 

Jonny Bekkum, Norway CslaContrib Coordinator

Not Ranked
9 Posts
Marsh replied on Wed, May 16 2012 3:23 AM

Thanks for your suggestions.

I am using Silverlight 5 MVVM with CSLA 4.2 and Error message should be shown in PropertyStatus.

I understand your first suggestion using attached a property and how to shown in property status on UI next or before to Datagridview. But it fires every time if any property in child object is changed not only when any object is added or removed from list.

regarding to "on the list property in "root" (- in WindowsForms will be shown next to a list/datagridview)", Does CSLA allow add rules directly on BusinessListBase and validate it when property changed?

But  if attached at object level, How should it display propertystatus? Does it update UI ? As per my understanding,  CheckObjectRules() does not update UI(PropertyStatus). Please correct me if i am wrong. 

Top 10 Contributor
1,764 Posts

Hi,

Well, you can inspect more details i ChildChangedEventArgs to restrict when the validation is triggered.

Yes, PropertyStatus does not (at current) support broken rules on object level.

Yes, you can add rules to ANY IPropertyInfo - but for child objects the validation rules are not automatically rechecked based on the ListChanged event.

Rules are normally triggered from PropertyHasChanged when the user edits a field (changes the value of the property and implicily called by SetProperty) or from BusinessRules.CheckRules().

 

Jonny Bekkum, Norway CslaContrib Coordinator

Page 1 of 1 (4 items) | RSS

Copyright (c) 2006-2010 Marimer LLC. All rights reserved.
Email admin@lhotka.net for support.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems