I want my seed method to first clear/drop the database and get rid of all the old data, however
context.Database.ExecuteSqlCommand("TRUNCATE TABLE [Purchases]");
context.Database.ExecuteSqlCommand("TRUNCATE TABLE [Invoices]");
gives me
Cannot truncate table 'Purchases' because it is being referenced by a FOREIGN KEY constraint.
because entries in Purchases are dependent on entries in Invoices. How can I clear all the data via the seed method?
edit: These are the relevant models:
public class Invoice
{
//Primary Key
public int InvoiceID { get; set; }
//Misc. info
public DateTime CreationDate { get; set; }
public DateTime DeadlineDate { get; set; }
public string ReceiverName { get; set; }
//Order details
public virtual List<Purchase> Purchases { get; set; }
//Auto-calculated property
[DataType(DataType.Currency)]
public float TotalCost { get; set; }
//Invoice author info
public string AuthorName { get; set; }
public string AuthorID { get; set; }
}
public class Purchase
{
public int PurchaseID { get; set; }
public string ProductDescription { get; set; }
public float SinglePrice { get; set; }
public float Amount { get; set; }
public float TotalPrice { get { return Amount * SinglePrice; } }
}