我使用的是MVC2,我正在关注MvcMusicStore上的教程。问题是总数不在数据库的Orders表中更新。每次我从网站订购一些东西,然后进入数据库时,Total
字段仍然表示0.00。有没有人知道这一点。下面是代码:MvcMusicStore教程中的数据库上的总数未更新? MVC2
public int CreateOrder(Order order)
{
decimal totalOrder = GetTotal();
var cartItems = GetCartItems();
//Iterate the items in the cart, adding Order Details for each
foreach (var cartItem in cartItems)
{
var orderDetails = new OrderDetail
{
ProductId = cartItem.ProductId,
OrderId = order.OrderId,
UnitPrice = cartItem.Product.Price,
Quantity = cartItem.Count
};
cricket_Model.OrderDetails.AddObject(orderDetails);
totalOrder = (cartItem.Count * cartItem.Product.Price);
}
// Set the order's total to the orderTotal count
order.Total = totalOrder;
//Save the order
cricket_Model.SaveChanges();
//Empty the shopping cart
EmptyCart();
//Return the OrderId as a confirmation number
return order.OrderId;
}
我只想说,在Order
表除了Total
领域OrderDetails
表,一切一切的更新更新。
它在调试模式下显示totalOrder值吗?使用.SaveChanges()方法或totalOrder本身是否为0.00? – Priyank 2011-05-02 15:09:35