Context.SubmitChanges不起作用 [英] Context.SubmitChanges doesn't work
本文介绍了Context.SubmitChanges不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不明白为什么更改无法保存.
确保为主键设置了productID.
有什么想法吗?
I don''t understand why the changes doesn''t get saved.
productID is set for primarykey for sure.
any ideas???
public void UpdateProductSupplierUnitPrice(POrder order)
{
foreach (var item in order.POrderItems)
{
Product product = new Product
{
ProductID = item.ProductID,
SupplierID = order.SupplierID,
UnitPrice = item.UnitPrice
};
masterRepository.SaveProduct(product);
}
}
public void SaveProduct(Product product)
{
if (product.ProductID == 0)
{
product.CreatedBy = Convert.ToInt32(HttpContext.Current.User.Identity.Name);
product.CreatedOn = DateTime.Now;
productTable.InsertOnSubmit(product);
}
else
{
product.UpdatedBy = Convert.ToInt32(HttpContext.Current.User.Identity.Name);
product.UpdatedOn = DateTime.Now;
}
productTable.Context.SubmitChanges();
}
推荐答案
// Create a new Order object.
Order ord = new Order
{
OrderID = 12000,
ShipCity = "Seattle",
OrderDate = DateTime.Now
// …
};
// Add the new object to the Orders collection.
db.Orders.InsertOnSubmit(ord);
// Submit the change to the database.
try
{
db.SubmitChanges();
}
catch (Exception e)
{
Console.WriteLine(e);
// Make some adjustments.
// ...
// Try again.
db.SubmitChanges();
}
使用上面的代码作为示例,请尝试这种方式.
希望这会有所帮助!!!
Use above code as sample, try this way.
Hope this will help !!!
这篇关于Context.SubmitChanges不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文