New Posts New Posts RSS Feed: Many-to-Many table problem
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Many-to-Many table problem

 Post Reply Post Reply
Author
GregD View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 374
Post Options Post Options   Quote GregD Quote  Post ReplyReply Direct Link To This Post Topic: Many-to-Many table problem
    Posted: 04-Jan-2008 at 10:38am
I guess I really don't understand the issue, then.
 
The sequence number is just a property of the linking object. Why should there be any problem modifying it?  It is just like any (non-read-only) property of any object!
 
If you change the value of the SequenceNumber property of existing linking objects; or you add new linking objects; or you delete existing linking objects, no matter: as soon as you ask the User object for its related Roles, you'll get the current list of many-to-many relatives, sorted in the current Sequence order.
 
What am I missing?
 
 
Back to Top
darbuc View Drop Down
Newbie
Newbie
Avatar

Joined: 14-Dec-2007
Posts: 2
Post Options Post Options   Quote darbuc Quote  Post ReplyReply Direct Link To This Post Posted: 04-Jan-2008 at 3:00am

Thanks for the response.

The challange here is that the "sequence" number can change, or items
can be added into the list, which will change the "execute sequence" and the effect of this will have to be cascaded back through the 'join" table.
 
Your example will useful in diplaying  the collection in the correct "sequence" number, but being able to modify this number is where I got stuck...
 
Thanks
 
 
 
 
 
Back to Top
GregD View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 374
Post Options Post Options   Quote GregD Quote  Post ReplyReply Direct Link To This Post Posted: 03-Jan-2008 at 5:43pm

>> In your examples, one is generally only adding or removing items from the "join-table", not trying to modify this entity.

But realize, every time we add an Order to the Order table, we are, in effect, creating a linking entity between an Employee (acting as SalesRep) and a Customer (who placed the Order). So there's nothing at all unusual or improper about your requirement. The linking entity can have as many properties on it as you need, and can be a meaningful entity in its own right (as is Order).
 
Here's a many-to-many Roles property definition that return a user's collection of Roles, sorted in descending order by the Id property of the UserRole (the linking object).  (Since I didn't have a SequenceNumber column in my UserRole table, I just used the Id.)
 

public EntityList<Role> Roles {

get {

ReadOnlyEntityList<UserRole> userRoles = base.UserRoles;

userRoles.ApplySort(EntityPropertyDescriptors.UserRole.Id.Name,

System.ComponentModel.ListSortDirection.Descending, false);

EntityList<Role> roles = new EntityList<Role>();

foreach (UserRole aUserRole in userRoles) {

roles.Add(aUserRole.Role);

}

return roles;

}

}

 
Back to Top
darbuc View Drop Down
Newbie
Newbie
Avatar

Joined: 14-Dec-2007
Posts: 2
Post Options Post Options   Quote darbuc Quote  Post ReplyReply Direct Link To This Post Posted: 14-Dec-2007 at 4:58am

 

Hi

I have a one-to-many relationship that I am trying to implement.(not unlike your User/User Role example)

The difference being that on the "join table" there is a sequence number, which determines the execute sequence that the items joined by the many-to-many table will need to be executed in.

(this can also be be changed at any time)

I am struggling to work out how to get this to work with ideablade

In your examples, one is generally only adding or removing items

from the "join-table", not trying to modify this entity.

Maybe having the sequnce number on the "join-table" is not

"best practice". But I'm not quite sure how to best implement

this requirment.

An example would be, that maybe you want to have a sort-order on UserRoles that diplayed the roles in a particular order. Not just
Ascending/Descending.
Any suggestions would be appreciated.

Thanks.

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down