What to do when the table is both a Parent and Child

What to do when the table is both a Parent and Child

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


dhtroy posted on Friday, August 22, 2008

I'm new to CSLA, and have been thrown into this rather quickly; I've tried searching for this answer already but haven't been able to locate it (most likely because I'm not entirely certain how to word what I'm searching for)

I have a table that is both a parent to another table (one-to-many relationship) and has a (many-to-one) relationship with two other tables; in my attached diagram, this table would be the "book reports" table (real table names changed to protect the innocent).

We use NHibernate to map from the Database to DTOs, and then CSLA for our Business objects. My problem is how to properly set-up my business object so that I can get/set instances of the "Student" and "Teacher" objects through the "Book Reports" business object. (I hope that makes sense).

Can someone please point me in the right direction?

Thank you.

sergeyb replied on Friday, August 22, 2008

I think the answer would depend on UI. Are you showing all book reports or are you picking a student or teacher first to narrow down book reports?

 

Sergey Barskiy

Principal Consultant

office: 678.405.0687 | mobile: 404.388.1899

Magenic ®

Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: dhtroy [mailto:cslanet@lhotka.net]
Sent: Friday, August 22, 2008 9:38 AM
To: Sergey Barskiy
Subject: [CSLA .NET] What to do when the table is both a Parent and Child

 

I'm new to CSLA, and have been thrown into rather quickly; I've tried searching for this answer already but haven't been able to locate it (most likely because I'm not entirely certain how to word what I'm searching for)

I have table that is both a parent to another table (one-to-many relationship) and has a (many-to-one) relationship with two other tables; in my attached diagram, this table would be the "book reports" table (real table names changed to protect the innocent).

We use NHibernate to map from the Database to DTOs, and then CSLA for our Business objects. My problem is how to properly set-up my business object so that I can get/set instances of the "Student" and "Teacher" objects through the "Book Reports" business object. (I hope that makes sense).

Can someone please point me in the right direction?

Thank you.


dhtroy replied on Friday, August 22, 2008

Thanks for the quick response:

We're showing all book reports in a list.

sergeyb replied on Friday, August 22, 2008

Ok, then here is my take on design:

 

1.       BookReports (BLB)

a.       Book Report (BB)

i.         Teacher (one, not list since it is 1-n relationship, probably ROB if you cannot modify it, which is my assumption)

ii.       Student (one, not list since it is 1-n relationship, probably ROB if you cannot modify it, which is my assumption)

 

I would load appropriate teacher and student during fetch of each Book Report.

 

Sergey Barskiy

Principal Consultant

office: 678.405.0687 | mobile: 404.388.1899

Magenic ®

Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: dhtroy [mailto:cslanet@lhotka.net]
Sent: Friday, August 22, 2008 9:53 AM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] RE: What to do when the table is both a Parent and Child

 

Thanks for the quick response:

We're showing all book reports in a list.


dhtroy replied on Friday, August 22, 2008

Yes, your assumption regarding having Teacher/Student read-only is correct.

Using what you've stated here, I believe I know what implementation changes I need to make.

Thank you for the insight.

TheSquirrelKing replied on Friday, August 14, 2009

Apologies for dredging up such an old thread, but, out of curiosity, would you suggest that the Teacher property in BookReport should be an instance of a TeacherInfo object or just its ID? I've gone with the former out of habit, but the latter option binds more nicely to TeacherList (in the same way as with NameValueLists) and lightens the BookReport object a bit. Of course, this comes with the downside of having to call TeacherInfo.GetTeacherInfo(<BookReport instance>.Teacher) anytime you want to use the TeacherInfo object in any way.

dhtroy replied on Friday, August 14, 2009

No worries; I ended up using just the ID of the "Teacher" and "Student" in the BookReport, and I programmatically load those objects on an "as needed" basis, because at the time, our framework was still in the process of being developed, and there were some design issues in our repository layer (which have all been resolved).

If I were doing it today, I'd probably just add Teacher/Student info lists to the BookReport; but I would only do so if I knew for certain that (1) those info lists were very lightweight and (2) those lists would be small.

Larger lists ... I would find a way to lazy load them, if possible; obviously, you don't want your users having to sit there waiting for an object to hydrate with a bunch of child collections, when they only plan to edit a single property on the parent record to begin with ...




Copyright (c) Marimer LLC