Я хочу разработать базу данных для теста по английскому языку
Это тест с четырьмя вариантами ответов
это моя диаграмма БД:

но я чувствую, что мой дизайн неверно (особенно внешние ключи)
потому что добавить вопрос очень и очень сложно
это мой класс для кода структуры сущности в первую очередь =
Код: Выделить всё
public class QuestionTable
{
[Key]
public int Id { get; set; }
public string Question { get; set; }
public virtual List AnswerTables { get; set; }
}
public class AnswerTable
{
[Key]
public int Id { get; set; }
public string Answer { get; set; }
public bool Correct { get; set; }
public virtual QuestionTable FK_que { get; set; }
}
public class UserTable
{
public int Id { get; set; }
public string Username { get; set; }
public virtual QuestionTable FK_que { get; set; }
public virtual AnswerTable FK_ans { get; set; }
}
Код: Выделить всё
[HttpGet("init")]
public string Init()
{
//--------------------------------------------------------------------
var f = new QuestionTable { Question = "question1" };
_context.QuestionTables.Add(f);
_context.SaveChanges();
//next init b.Id == 2
var a = (from b in _context.QuestionTables where b.Id == 1 select new { b.Id }).Single().Id;
var c = _context.QuestionTables.Find(a);
var obj1 = new QuestionTable()
{
Question = "question1",
AnswerTables = new List
{
new AnswerTable{Answer="answer1",Correct=false,FK_que=c},
new AnswerTable{Answer="answer2",Correct=false,FK_que=c},
new AnswerTable{Answer="answer3",Correct=false,FK_que=c},
new AnswerTable{Answer="answer4",Correct=true,FK_que=c},
}
};
_context.QuestionTables.Add(obj1);
_context.QuestionTables.Remove(f);
_context.SaveChanges();
//-------------------------------------------------------------------------
return "C# : it was hard but we made it !";
}
Источник: https://stackoverflow.com/questions/781 ... sql-server