Model design

Model design

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


meierk posted on Thursday, December 20, 2007

I am a Delphi developer who is just learning .NET and I have a lot of confusion that I am trying to work out one piece at a time.  I read the CSLA book about a year ago so I have some knowledge of the framework and concepts, but no practical experience with it.  Hopefully you don't mind me vetting my class design with you.

I am working with an existing database that I cannot change and I will be working with the following tables and implyed relationships

Bend (a single Bend has only 1 or 2 BendDetails)
   BendDetails (a single BendDetail has 1 to 9 Bend Readings and 0 to 9 Inspection Readings)
      BendReadings
      BendInspReadings

From my tables I was going to create the following classes using CodeSmith:
My Winform application will have the following two forms for editing:
  1. The Bender form opens after the use selects a Bend to edit from the ReadOnly Bend list on the main form.  It will have controls bound to the Bend class and two DataGridView controls bound to the BendDetails and BendReadings collections.  The BendReadings is dependant on the BendDetails collection, meaning that it will change as the user selects a BendDetail in a grid.
  2. The Quality Control form is similar to the Bender form, with the difference being that it uses the BendInspectionReadings collection instead of the BendReadings collection.
Does the list of classes seem reasonable to you given the limited detail I have provided?

Kevin

JoeFallon1 replied on Thursday, December 20, 2007

Kevin,

It looks exactly right to me. It should work well. Good luck with the project.

Joe

meierk replied on Friday, December 21, 2007

Thanks for the reply Joe.  One thing I haven't figured out yet is the data loading so hopefully you have some tips or insight for me.  The code that the CodeSmith templates generate use Stored Procs to load the data.

Would you advise that the I use one stored proc that returns multiple result sets and have the parent pass the datareader to each collection or should I have a SP for each class and have them responsible for loading there own data?  In my case, I will only load 29 rows max between Bend, BendDetails, BendReading and BendInspectionReadings.

Kevin

JoeFallon1 replied on Friday, December 21, 2007

Kevin,

I do not use SPs. I use dynamic SQL statements instead. But the concepts are the same. When their is a graph 2 levels deep (parent / child relationship) it is "obvious" that the parent should fetch itself and then pass the dr to the child to fetch it.

It gets a bit trickier when the graph is 3 or more levels deep. Just search for "grandchild" in this forum and you should see many hits. Rocky also has a "deep data" sample which handles this type of thing. So you can investigate that if the other options are not appealing to you.

1. I think some people retrieve a dataset that handles all the various relationshis and then they populate thier objects from that.

2. I use the method in the 1st paragraph for the first 2 levels. But when each child needs to fetch its grandchild I open a 2nd connection and create a new datareader and pass it in. This technique is acceptable to me. I have not had any performance issues related to it. Some may object to the chattiness - but it is not flatteing the hierarchy and bringing back "too much data" either. So there are trade offs in both approaches.

Joe

 

Copyright (c) Marimer LLC