I have two models:
public class Customer : People
{
public int CustomerID { get; set; }
public decimal? Weight { get; set; }
public decimal? Height { get; set; }
public ICollection<Purchase> Cart { get; set; }
}
and
public class Purchase
{
public int PurchaseID { get; set; }
public DateTime Time { get; set; }
public decimal TotalPrice { get; set; }
public int Amount { get; set; }
public Good Good { get; set; }
}
I already have a customer and need to update his Cart (to add smth to it for example).
I've tried to do smth like this but this do nothing. What am i doing wrong?
Customer customer = new Customer()
{
CustomerID = currentID.Value
};
var cart = new List<Purchase>();
cart.Add(new Purchase()
{
Amount = 1,
Good = good,
Time = DateTime.Now,
TotalPrice = good.Price
});
customer.Cart = cart;
var entry = _context.Entry(customer);
_context.Update(customer);
_context.SaveChanges();
UPDATE:
I've tried to do suggested things but.. What i don't understand right in my life? Context when i try to update vs. Context when i try to view updated Customer