0
:アップデートいるICollection(Entity Frameworkの6、ASP.NETコア)
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; }
}
と
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; }
}
を私はすでに顧客を持っているし、彼のカートを更新する必要があります(へそれにsmthを追加するなど)。
私はこれのようにスムーズをしようとしましたが、これは何もしません。何が間違っているのですか?
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:
私は提案のことを行うことを試みましたが、..私は私の人生の中で権利を理解していませんか? Context when i try to updateと対
'var entry = _context.Entry(customer);'ちょうど好奇心のため、どこでエントリ変数を使用していますか? –
私は[このガイド](http://stackoverflow.com/a/15339512/5380012)に従いましたが、 'entry.Property(e => e.Cart).IsModified = true;で例外がありました。だから私はこの行を削除して質問に追加するのを忘れてしまった – Sergey