Question

Right-click on the /Data/Models/ folder and add a Question.cs class file with the following code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace TestMakerFreeWebApp.Data
{
public class Question
{
#region Constructor
public Question()
{

}
#endregion

#region Properties
[Key]
[Required]
public int Id { get; set; }

[Required]
public int QuizId { get; set; }

[Required]
public string Text { get; set; }

public string Notes { get; set; }

[DefaultValue(0)]
public int Type { get; set; }

[DefaultValue(0)]
public int Flags { get; set; }

[Required]
public DateTime CreatedDate { get; set; }

[Required]
public DateTime LastModifiedDate { get; set; }
#endregion
}
}

That’s it. Note the QuizId foreign key we have here instead of the UserId; this is because each question is a child element of the quiz, so we don't need an UserId property, we'll just fetch the value from the parent.

It's important to understand that the preceding assumption is true only if we can take for granted that the quiz author will be the only user allowed to add/manage questions to each quiz; this is precisely what we're about to do, hence, the UserId property can be omitted.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.171.125