m:n

4 posts, 1 answers
  1. Stuart Hemming
    Stuart Hemming avatar
    1622 posts
    Member since:
    Jul 2004

    Posted 06 Jul 2010 Link to this post

    I have a "DClass" class representing a class taught at a school. I also have a "Student" class. A DClass can have many Students and a Student may attend many classes. To this end I added IList<> properties to each of the classes representing the list of the 'opposite' type. I also created a "Registration" class to join the 2. So far no problems. I need to record some data against each DClass/Student pairing, a fee paid, for example. So, I added my "FeePaid" property to my "Registration" class. Again, no problem.

    My problems start when I actually try to get OA to accept my table as the link table. Nothing I try seems to allow me to convince OA to use my table. I briefly thought I should let OA create the table and then alter it but the link table doesn't get added to the object model.

    I guess that this means that either OA is broken or I'm doing it wrong; My money's on the latter.

    Is it possible to get OA to use a user-defined class to link 2 others as described above?

    Or should I be doing it differently?

    Thanks in anticipation,

    -- 
    Stuart
  2. Answer
    TSE
    TSE avatar
    381 posts
    Member since:
    Sep 2008

    Posted 07 Jul 2010 Link to this post

    Hi Stuart,

    I am not sure if I fully understand your class model, but if you try to turn it 180 degrees around: What "connects" a Student and a Class - the Registration.

    So you can lay out your classes like:

    class Student
    {
     // 1:m inverse field mapped to student field on class Registration
     - IList<Registration> registrations
    }

    class Registration
    {
     - Student student
     - Class class
     - double fee
    }


    class Class
    {
     // 1:m inverse field mapped to class field on class Registration
     - IList<Registration> registrations
    }

    So it is the Registration that connects a student to a list of classes and vice versa
    Note, that you do not have a m:n relationship between the Student and Class class, instead you have a 1:m to the Registration class from the other two (in the IList<Registration> registrations field).
    Doing so will make the Registration class the "join table class" and it will allow you to store additional information in this "join table class"..

    Regards

    Henrik


  3. DevCraft banner
  4. Stuart Hemming
    Stuart Hemming avatar
    1622 posts
    Member since:
    Jul 2004

    Posted 07 Jul 2010 Link to this post

    Henrik,

    Thanks.

    Thanks for helping me make a difficult decision. I've decided to give up programming and do something I'm clearly better qualified for, like selling ice-cream or helping kiddies across the road.

    Yea gods but I'm dim. I was concentrating that had on trying to shoe-horn my additional properties in to the m:n link table that OA created and then... Never mind

    If I'd done this with a pen and paper, or even by first creating the DB tables I'd've seen the answer straight-away, but I thought that I'd try and do everything using forward-mapping (to see if I could) and got lost in the trees.

    Thanks again matey.

    -- 
    Stuart (now, where did I put that application form for Ben and Jerry's ...?)
  5. TSE
    TSE avatar
    381 posts
    Member since:
    Sep 2008

    Posted 07 Jul 2010 Link to this post

    Hi Stuart,

    I must admit I am setting here with a BIG smile on my lips as for your comments on Ben & Jerry's (nice tasting ice by the way) :-)

    Glad I could help, maybe you can go to their website to get a form?  :-)

    Regards

    Henrik
Back to Top