I have created a seed method and it is failing to populate my 'Ticket' table. The other two tables have been populated fine.
Here is error displayed in the Package Manager Console:
Cannot insert the value NULL into column 'TicketID', table 'OnlineTicketSystemContext.dbo.Tickets';
column does not allow nulls.
INSERT fails.
Here is my seed method for the 'Ticket' table which will not populate:
var tickets = new List<Ticket>
{
new Ticket{
EmployeeID = employees.Single(s => s.Surname == "Alexander").EmployeeID,
CustomerID = customers.Single(c => c.Surname == "Marsden").CustomerID,
Summary = "Broken laptop screen",
StartDate = DateTime.Parse("04/05/2012"),
DueDate = DateTime.Parse("10/05/2012"),
HardwareDelivered = true,
Status = Status.Open,
Priority = Priority.High
},
new Ticket{
EmployeeID = employees.Single(s => s.Surname == "Marshall").EmployeeID,
CustomerID = customers.Single(c => c.Surname == "Copper").CustomerID,
Summary = "Keyboard doesnt work",
StartDate = DateTime.Parse("09/07/2012"),
DueDate = DateTime.Parse("12/07/2012"),
HardwareDelivered = true,
Status = Status.Open,
Priority = Priority.High
}
};
foreach (Ticket t in tickets)
{
var ticketInDataBase = context.Tickets.Where(
s =>
s.Employee.EmployeeID == t.EmployeeID &&
s.Customer.CustomerID == t.CustomerID).SingleOrDefault();
if (ticketInDataBase == null)
{
context.Tickets.Add(t);
}
}
context.SaveChanges();
Here is the Ticket model:
public class Ticket
{
public int TicketID { get; set; }
public int EmployeeID { get; set; }
public int CustomerID { get; set; }
public string Summary { get; set; }
public DateTime StartDate { get; set; }
public DateTime DueDate { get; set; }
public Boolean HardwareDelivered { get; set; }
public Status? Status { get; set; }
public Priority? Priority { get; set; }
public virtual Employee Employee { get; set; }
public virtual Customer Customer { get; set; }