장바구니에서 주문 목록을 추가하려고합니다. 내가) (http://www.asp.net/mvc/tutorials/mvc-music-store/mvc-music-store-part-9MVC3 db.SaveChanges() 내부 예외
db.saveChanges 마찬가지로 이렇게 오류가 있어요
항목을 업데이트하는 동안, '오류가 발생했습니다. 자세한 내용은 내부 예외를 참조하십시오. '
주문을 볼 때 orderId는 '0'입니다. 이것에 문제가 있습니까?
몇 가지 코드를 제공합니다.
몇 가지 아이디어를 제공해 주시겠습니까?
감사합니다.
//Order.cs
public class Order
{
rentalDB db = new rentalDB();
[Key] public int orderId { get; set; }
public int customerId { get; set; }
public DateTime orderDate { get; set; }
public int rentalPeriod { get; set; }
public DateTime startDate { get; set; }
public decimal total { get; set; }
public virtual Customer Customer { get; set; }
public List<OrderDetails> OrderDetails { get; set; }
}
여기 컨트롤러가 있습니다.
//AccountController.cs
[Authorize]
public ActionResult Order()
{
var order = new Order();
TryUpdateModel(order);
string customerName = User.Identity.Name;
if (customerName == "")
{
return RedirectToAction("LogOn", "Account");
}
int customerId = (from a in db.Customer
where a.userName == customerName
select a.customerId).Single();
order.customerId = customerId;
db.Order.Add(order);
//I added orderDate and startDate, then it is saving now.
order.orderDate = System.DateTime.Now;
order.startDate = System.DateTime.Now.AddDays(2);
db.SaveChanges();
var cart = ShoppingCart.GetCart(this.HttpContext);
cart.CreateOrder(order);
return View(order);
}
내부 예외는 무엇이라고 말합니까? – James