I have a shopping cart that is to receive items from two separate tables.
One table contains single items and the other contains Boxes of several items.
I am using an ApiController to insert the item into the cart, problem being that when I insert a Box with ID 1, the FK in Cart updates the ID to 1 but there is no indication to if it is an Item or Box.
I have tried to have multiple FK in cart table for each the Item and Box ID but Code first is giving errors about nulls in the FK. I have tried making them nullable but this causes errors when trying to join the tables for data retrieval.
What is the best practice for a relationship shown below?
Cart Model:
public class Cart
{
[Key]
public int RecordID { get; set; }
public string CartID { get; set; }
public int ItemID { get; set; }
public int BoxID { get; set; }
public int Qty { get; set; }
public System.DateTime DateCreated { get; set; }
public Item Item{ get; set; }
public Box Box { get; set; }
public string UserID { get; set; }
public ApplicationUser User { get; set; }
}