具有List <t>属性的实体未更新</t>

时间:2013-02-06 00:40:44

标签: c# entity-framework-5

以下代码无法按预期工作。在处理上下文后,item.ActiveEntries会更新并保留,user.ShoppingCart.Cart。此外,这两个属性都定义为virtual List<CartEntry>

using (var context = new LocabalSqlContext())
{
    var user = Auth.GetUser(context);
    var item = context.Items.First();
    var entry = new CartEntry()
    {
        Item = item,
        Quantity = 3,
        LastRefresh = DateTime.Now
    };
    item.ActiveEntries.Add(entry);
    user.ShoppingCart.CartEntries.Add(entry);
}

0 个答案:

没有答案