示例#1
0
 public void UpdateQuestion(Question updateQuestion)
 {
     using (var db = new QuizModel())
     {
         db.Questions.Attach(updateQuestion);
         var entry = db.Entry(updateQuestion);
         entry.State = System.Data.Entity.EntityState.Modified;
         foreach (var answer in updateQuestion.Answers)
         {
             var answerEntry = db.Entry(answer);
             answerEntry.State = System.Data.Entity.EntityState.Modified;
         }
         db.SaveChanges();
     }
 }
示例#2
0
 public Question GetQuestionById(int id)
 {
     using (var db = new QuizModel())
     {
         var question = db.Questions.Find(id);
         db.Entry(question).Collection(q => q.Answers).Load();
         return(question);
     }
 }