Linq To Sql - DataContext.SubmitChanges() 问题
我有一个这样的代码。
DBContext是Datacontext实例。
try
{
TBLORGANISM org = new TBLORGANISM();
org.OrganismDesc = p.Subject;
DBContext.TBLORGANISMs.InsertOnSubmit(org);
DBContext.SubmitChanges();
}
catch (Exception)
{
}
此时,我想忽略该错误并希望被跳过。不得重试。 但是,当我尝试另一个插入(例如
TBLACTION act = new TBLACTION();
act.ActionDesc = p.ActionName;
DBContext.TBLACTIONs.InsertOnSubmit(act);
DBContext.SubmitChanges();
SubmitChanges)时,首先会重试之前的尝试。
我怎样才能告诉“跳过错误,不要重试”?
I have a code like this.
DBContext is Datacontext instance.
try
{
TBLORGANISM org = new TBLORGANISM();
org.OrganismDesc = p.Subject;
DBContext.TBLORGANISMs.InsertOnSubmit(org);
DBContext.SubmitChanges();
}
catch (Exception)
{
}
At this point, I want to IGNORE the error and want to be skipped. Not to be retried.
But when I try another insert like
TBLACTION act = new TBLACTION();
act.ActionDesc = p.ActionName;
DBContext.TBLACTIONs.InsertOnSubmit(act);
DBContext.SubmitChanges();
SubmitChanges firstly retries previous attempt.
How can I tell "skip errors, don't try again"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
第二次创建 DBContext 的新实例。
但为什么要跳过错误呢?
Create a new instance of DBContext the second time.
But why do you want to skip errors?
试试这个:DBContext.SubmitChanges(ConflictMode.ContinueOnConflict)。
希望它会有所帮助。
Try this: DBContext.SubmitChanges(ConflictMode.ContinueOnConflict).
Hope it will help.