SQL - 多个一对多关系

问题描述 投票:1回答:2

有可能以某种方式在两个表之间进行多个一对多关系吗?喜欢:

表abc

  • abcID
  • defID
  • 信息

表定义

  • defID
  • abcID
  • 信息

如果是,我怎么能用实体框架创建一个新的abc条目?

sql entity-framework relationship
2个回答
2
投票

你只需要一个很多很多的关系。只需将QuestionId移出quiz_answers表,然后将AnswerId从quiz_questions表中移出:

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 )
)

0
投票

是的,它是从abc到def的一对一连接,然后是从def到abc的另一个连接;所以abc在defID上加入def def,在abcID上加入def到abc。

© www.soinside.com 2019 - 2024. All rights reserved.