Can anyone explain why I m sometimes gets a NULL exception on this insert method? As said is only sometimes, which for me is just even more confusing.
该表在数据目录(dbml文档)中载有产品一览表。
public void insertNewOrder(string accountNumber, int orderId)
{
var order = orderRep.GetOrderById(orderId);
var orderlineData = orderLineRep.GetOrderLines(order.OrderID);
foreach (var orderLine in orderlineData)
{
int currentStatus = dlvRep.getAxOrderStatusNumber(orderLine.ItemNumber, 0);
string levering = "";
string status = dlvRep.getAxOrderStatus(orderLine.ItemNumber, currentStatus, out levering);
WebsiteOrderStatus insertNew = new WebsiteOrderStatus
{
AccountNumber = accountNumber,
OrderID = orderId,
ItemNumber = orderLine.ItemNumber,
ItemName = orderLine.Product.Name,
FormatName = orderLine.Product.ProductFormatName,
Quantity = orderLine.Quantity,
Price = orderLine.Price,
Status = status,
Levering = levering,
LastUpdatedStatus = currentStatus,
CreatedDate = DateTime.Now
};
db.WebsiteOrderStatus.InsertOnSubmit(insertNew);
db.SubmitChanges();
}
}
特殊信息:
Cannot insert the value NULL into column FormatName , table GWportal.dbo.WebsiteOrderStatus ; column does not allow nulls. INSERT fails.
声明已终止。
当我看看一下该法典正在发现产品“FormatName”时。 产品产品价值不是NUL,它具有我预期的价值:“PS3”。
另一个奇怪之处是,为什么有人抱怨:
ItemName = orderLine.Product.Name,
这部法律不允许无效。