CSLA .NET

From Rockford Lhotka's Expert C# 2005 and VB 2005 Business Objects books

Welcome to CSLA .NET Sign in | Join | Help
in Search

Clarification of populating grandchildren and saveable broken rules objects

Last post 11-15-2006, 5:08 PM by david.wendelken. 11 replies.
Sort Posts: Previous Next
  •  06-19-2006, 4:54 AM 1971

    Clarification of populating grandchildren and saveable broken rules objects

    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.

  •  06-19-2006, 7:07 AM 1974 in reply to 1971

    Re: Clarification of populating grandchildren and saveable broken rules objects

    Attachment: SafeDataRowReader.zip
    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.
  •  06-19-2006, 12:32 PM 2008 in reply to 1971

    Re: Clarification of populating grandchildren and saveable broken rules objects

    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

  •  06-20-2006, 2:57 AM 2046 in reply to 2008

    Re: Clarification of populating grandchildren and saveable broken rules objects

    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.

  •  06-20-2006, 11:12 AM 2073 in reply to 2046

    Re: Clarification of populating grandchildren and saveable broken rules objects

    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?
  •  06-20-2006, 1:15 PM 2079 in reply to 2073

    Re: Clarification of populating grandchildren and saveable broken rules objects

    malloc,

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

    Andy
  •  06-20-2006, 3:42 PM 2094 in reply to 2073

    Re: Clarification of populating grandchildren and saveable broken rules objects

    Perhaps they would be more appropriate as a wiki pages instead of a forum topics?
  •  06-21-2006, 7:03 AM 2110 in reply to 2094

    Re: Clarification of populating grandchildren and saveable broken rules objects

    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.
  •  06-21-2006, 7:10 AM 2112 in reply to 2110

    Re: Clarification of populating grandchildren and saveable broken rules objects

    I could not agree more!!!
  •  06-21-2006, 7:40 AM 2118 in reply to 2112

    Re: Clarification of populating grandchildren and saveable broken rules objects

    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.
  •  11-15-2006, 11:01 AM 9270 in reply to 1974

    Re: Clarification of populating grandchildren and saveable broken rules objects

    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.
  •  11-15-2006, 5:08 PM 9287 in reply to 2008

    Re: Clarification of populating grandchildren and saveable broken rules objects

    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.

View as RSS news feed in XML

Please contact Magenic for your .NET consulting and CSLA .NET mentoring needs.
Please consider making a donation to help support the ongoing development of CSLA .NET.

Make donation through PayPal - it's fast, free and secure!
Why donate?
Powered by Community Server, by Telligent Systems