views:

50

answers:

2

Is it possible somehow to do multiplie one-to-many relationships between 2 tables? Like:

Table abc

  • abcID
  • defID
  • message

Table def

  • defID
  • abcID
  • message

If yes how can I then make a new abc entry with the entity framework?

+1  A: 

You only need a single Many-Many relationship. Simply move QuestionId out of the quiz_answers table and move AnswerId out of the quiz_questions table:

Create Table quiz_questions
(
QuestionId ... Not Null Primary Key
, Question ...
, ...
)

Create Table quiz_answers
(
AnswerId ... Not Null Primary Key
, Answer ...
, ...
)

Create Table quiz_question_answers
(
QuestionId ... Not Null References quiz_questions ( QuestionId )
, AnswerId ... Not Null References quiz_answers ( AnswerId )
, Constraint PK_quiz_question_answers Primary Key ( QuestionId, AnswerId )
)
Thomas
How do I know that AnswerId 7 belongs to QuestionId 2 then?
ebb
@user407674 - Because you will have a row in the quiz_question_answers table mapping QuestionId 2 to AnswerId 7. You may be seeking two Many-Many relationships: one to map *available* answers to question and another to map *actual* answers which would entail another vector which is the person making choosing the answer.
Thomas
Ah, I see.. Perfect - Thanks!
ebb
A: 

Yes, it is a one-to-one join from abc to def and then another from def back to abc; so abc joins to def on defID and def joins to abc on abcID.

EchoCoder