Clarification of populating grandchildren and saveable broken rules objects

Clarification of populating grandchildren and saveable broken rules objects

Old forum URL: forums.lhotka.net/forums/t/407.aspx


Coxy posted on Monday, June 19, 2006

Hi,

I've worked my way through most of the Expert C# 2005 Business Objects book and am about to start my first project using CSLA 2.0.2. However there are still 2 issues that I'm not clear on even after reading through the same issues on searchcsla.com.

Part of my object hierarchy looks like this

UnderwritingEnquiry (EditableRoot)

   -> Applicants (EditableChildCollection)

      -> Applicant (EditableChild)

         -> AddressHistory (EditableChildCollection)

            -> Address (EditableChild)

1) Loading grandchildren

It seems that a lot of people are using an extension developed by a member of the forum (SafeRowReader) for populating object graphs more than two levels deep. I can't seem to find an example of using this code or the actual class itself (attachments to posts don't seem to be available from searchcsla.com). Surely something this common should be added to the framework and explained in the book, or at the very list shown in the example ProjectTracker application?

2) Severity of business rules

Again this seems to have been solved by multiple members of the forum in different ways but I can't seem to find any code. The default implementation in CSLA automatically stops an object from being saved if any business rules are broken. This does not seem granular enough for a lot of business cases. For instance in my model, these are some of the business rules

   i) An applicant must have a name and telephone number.

   ii) An applicant must have at least 3 years address history.

If rule i) is broken then the object should be prevented from being saved. However if rule ii) is broken then the object should still be allowed to be saved even though the error should still be displayed to the user. By default, the UI developer shouldn't have to worry about the difference between the different severitiy levels unless they have a specific requirement.

 

Any help tracking down the code that is alluded to on searchcsla.com would be much appreciated.

 

Thanks,
Coxy.

Brian Criswell replied on Monday, June 19, 2006

Well, I can help you with the grandchild objects.  I fiddled a bit with the old SafeRowReader and gave it the ability to automatically sort out which rows belonged to which parent.  Add the included files to the Csla.Data folder.  If you want, you can change Csla.Data.SafeDataReader to implement ISafeDataReader instead of IDataReader.  Rudimentary example follows.  I will be able to answer questions later tonight.

// In root object fetch
using (DataSet results = new DataSet)
{
    // Fill DataSet
    // Add DataRelations to link tables
    using (SafeDataRowReader dr = new SafeDataRowReader(results.Tables[0].Rows))
    {
        // Read root object values using dr.Get...("ColumnName");

       using (SafeDataRowReader childDr = dr.GetData())
       {
          // Read first child's values
          dr.NextResult()
          // Read next child's values
          // etc.
       }
    }
}

// In a child object that has grandchildren
private void Fetch(ISafeDataReader dr)
{
    // Read values
 
    using (SafeDataRowReader childDr = dr.GetData())
    {
       // Read first child's values
       dr.NextResult()
       // Read next child's values
       // etc.
    }
}

So try it out and see if it works for you.  The implementation of dr.GetBytes might be a bit dodgy as I have not had much of an opportunity to test it.  I also may have made too many assumptions with dr.GetData to fit how the majority of people would want to use it.

Truth replied on Wednesday, November 15, 2006

Brian,

Reviving an old thread. Do you have any more recent example code of using your SafeDataRowReader?

Also, in the example:

       using (SafeDataRowReader childDr = dr.GetData())
       {
          // Read first child's values
          dr.NextResult()
          // Read next child's values
          // etc.
       }

Do you actually mean to execute childDr.NextResult or is the code correct?  Trying to determine what you are doing with dr.NextResult.

I see the same thing in thise post too.
http://forums.lhotka.net/forums/post/3541.aspx


Thanks for any assistance.

malloc1024 replied on Monday, June 19, 2006

Loading grandchildren has been discussed numerous times in the old forum.  One of the most common ways is to use a dataset.  You could also load the children first, close the data reader and then load the grandchildren.  Both options are not ideal, but they do the job.  If you want more ideas try seacrchcsla.com.  You might not get code that you can plug into your project directly, but you should be able to figure it out.

 

Business Rules Severity was just discussed in depth last week.  This has also been discussed numerous times in the old forum.  There are many ways to approach this problem and there is no official answer.

 

There are no official answers to your questions.  There are simply many ways to solve the issues you brought up.  Take a look at the alternatives and choose the ones you like best.

 

Below are some links that discuss the issues that you brought up.

 

Loading grandchildren:

http://www.lhotka.net/Articles.aspx?id=8354fb43-f676-48dc-b6a8-692f7ba27bb0

Severity of Business Rules:

http://forums.lhotka.net/forums/1/1745/ShowThread.aspx

Coxy replied on Tuesday, June 20, 2006

Thank you both, that's very helpful.

I'll look at updating the wiki for these issues once I've got some code working. Although not too difficult to sort out, they do seem very common for developers new to CSLA.

malloc1024 replied on Tuesday, June 20, 2006

The issues that you brought up are very common for people new to CSLA.  I would like to see these issues answered and placed in a closed thread called "For Beginners".  This thread should always remain on top so it is easy for people to see.  This would make it easier for new users to get the answers they need.  Many other forums have a closed thread called "For Beginners".  I think this would be very benifical to this fourmn.  What do others think about this idea?

ajj3085 replied on Tuesday, June 20, 2006

malloc,

I agree, and actually suggested this in the Forum administration section.  Didn't get any feedback though.

Andy

Brian Criswell replied on Tuesday, June 20, 2006

Perhaps they would be more appropriate as a wiki pages instead of a forum topics?

ajj3085 replied on Wednesday, June 21, 2006

The problem with seperate Wiki pages is that people will likely still come here first instead of going to the Wiki, and post their question anyway.  If its a 'sticky' forum topic, hopefully they'll be more inclined to read the topic.

PitDog replied on Wednesday, June 21, 2006

I could not agree more!!!

ajj3085 replied on Wednesday, June 21, 2006

If you want to keep discussing the FAQ idea, you should probably move the discussion to this thread: http://forums.lhotka.net/forums/thread/1516.aspx.  Don't want this thread to get any more off-topic.

david.wendelken replied on Wednesday, November 15, 2006

malloc1024:

Business Rules Severity was just discussed in depth last week.  This has also been discussed numerous times in the old forum.  There are many ways to approach this problem and there is no official answer.

There are no official answers to your questions.  There are simply many ways to solve the issues you brought up.  Take a look at the alternatives and choose the ones you like best.

Severity of Business Rules:

http://forums.lhotka.net/forums/1/1745/ShowThread.aspx

v2.1 contains the capability to designate a rule as an Error, a Warning or an Informational Message.

It disallows saves on Errors.

For some rule extensions I've coded, see the CslaSrd sub-project in the CSLA Contrib solution.

Copyright (c) Marimer LLC