foreach (StockItem item in StockList)
{
Master master = new Master();
master.VoucherNo = BillNo;
master.Voucher = "Sales";
master.StockName = StockList[0].StockName;
master.Quantity = StockList[0].Quantity;
master.Unit = StockList[0].Unit;
master.Price = StockList[0].UnitPrice;
master.Amount = StockList[0].Amount;
dbContext.AddToMasters(master);
dbContext.SaveChanges();
}
Sale sale = new Sale();
sale.InvoiceNo = BillNo;
sale.Date = BillDate;
sale.Party = Customer;
sale.Amount = (decimal)TotalAmount;
dbContext.AddToSales(sale);
dbContext.SaveChanges();
StockList
如果有 n 行,则此代码仅添加所有 n 次的第一行。
代码有什么问题?