下面的代码是否存在如果两个人同时提交会检索到错误的 s.saleID 的风险?
protected void submitSale(int paymentTypeID)
{
tadbDataContext tadb = new tadbDataContext();
ta_sale s = new ta_sale();
decimal total = decimal.Parse(lblTotal.Value);
s.paymentTypeID = paymentTypeID;
s.time = DateTime.Now;
s.totalSale = total;
tadb.ta_sales.InsertOnSubmit(s);
tadb.SubmitChanges();
char[] drinksSeparator = new char[] {'|'};
char[] rowSeparator = new char[] { ':' };
string drinkString = lblSummaryQty.Value.Substring(0, lblSummaryQty.Value.Length - 1);
string[] arrDrinks = drinkString.Split(drinksSeparator);
foreach (string row in arrDrinks)
{
string[] arrDrink = row.Split(rowSeparator);
int rowID = Convert.ToInt16(arrDrink[0]);
int rowQty = Convert.ToInt16(arrDrink[1]);
ta_saleDetail sd = new ta_saleDetail();
sd.drinkID = rowID;
sd.quantity = rowQty;
sd.saleID = s.saleID;
tadb.ta_saleDetails.InsertOnSubmit(sd);
}
tadb.SubmitChanges();
}
}
如果是这样,我应该怎么做才能确保它是原子的?(我认为应该没问题,但要仔细检查!)