How to implement many-to-one relationships

How to implement many-to-one relationships

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


Patrick posted on Wednesday, December 10, 2008

Hi,

I have many tasks. Each task can have a picture and multiple tasks can also share the same picture.

In the database I have many-to-one relationship between tasks and pictures.

I have a grid with all my tasks. This is a editable business list with child objects.

Now the user says they want to add the same picture to e.g. the first 3 tasks.

How would this be done with CSLA.NET?

All 3 tasks should point to the same picture via the PictureID property.

One option seems to be to make pictures a child object of task.... but a child is normally saved after a parent and in this case the parent task would need the PictureID of the child when the task is saved. Also multiple tasks would point to the same child which might cause other difficulties....

Making the hierarchy start at the picture level doesn't seem to make sense either as the user is really working with a editable list of tasks in a grid...

Thanks for your thoughts,
Patrick

ajj3085 replied on Wednesday, December 10, 2008

I would think Picture and Task would be root BB subclasses.  You'd also have a ROL of PictureInfos, which your task would accept as the picture.  The Task would read relevent data from the PictureInfo so it can create the link.

Patrick replied on Wednesday, December 10, 2008

Thanks for answering.

ajj3085:
I would think Picture and Task would be root BB subclasses.

task needs to be a child of business list base as it's displayed in a grid I would think.
ajj3085:
You'd also have a ROL of PictureInfos, which your task would accept as the picture.  The Task would read relevent data from the PictureInfo so it can create the link.
At the moment the pictures are added they are not saved yet as the user can still undo the adding of the images.. So how would the sync of PictureID work?

Thanks,
Patrick

ajj3085 replied on Thursday, December 11, 2008

Ok, I misunderstood.  Hmm... It sounds like you'd need a Pictures BLB off whatever your root object is.  But it also seems like pictures can be used outside just that root BO, right?

Copyright (c) Marimer LLC