Adding entity to M:N relation question

Posts   
 
    
ChrisMoses
User
Posts: 18
Joined: 22-Feb-2005
# Posted on: 26-Nov-2005 05:55:00   

Hi, I can't seem to figure out how to add an entity to a M:N relation with the self-servicing templates

For example: students and classes

Should I do something like: thisClass.Students.Add(thisStudent)

where Students is mapped to the M:N Via JoinClassesToStudents And JoinClassesToStudents is the join or link table

Or should a manually create an entry for the join table and add it, or something else?

I've tried all these and others, nothing seems to work.

If someone could point me in the right direction, I would be very appreciative.

Thanks, Chris

ChrisMoses
User
Posts: 18
Joined: 22-Feb-2005
# Posted on: 26-Nov-2005 06:54:10   

hmmm...

Looks like it is not really related to the save routines at all. It is related to using GUIDs as keys.

The code above does not work if GUIDs are the keys because the keys are incorrect.

I solved this by simply creating a proxy for entity creation:

public sub CreateStudent() dim s as new student s.StudentID = guid.NewGUID s.Save End

After that, it appears to always return the correct studentID.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 26-Nov-2005 12:55:27   

Correct, you have to set Guid keys manually. This is because the value NEWID() calls inside the DB return can't be intercepted / returned back to the caller, like with identity values, as there's no equivalent for SCOPE_IDENTITY() or @@IDENTITY for newid() calls.

Frans Bouma | Lead developer LLBLGen Pro