DataContext.SubmitChanges 方法

定义

计算要插入、更新或删除的已修改对象的集,并执行相应命令以实现对数据库的更改。Computes the set of modified objects to be inserted, updated, or deleted, and executes the appropriate commands to implement the changes to the database.

重载

SubmitChanges()

计算要插入、更新或删除的已修改对象的集,并执行相应命令以实现对数据库的更改。Computes the set of modified objects to be inserted, updated, or deleted, and executes the appropriate commands to implement the changes to the database.

SubmitChanges(ConflictMode)

将对检索到的对象所做的更改发送到基础数据库,并指定提交失败时要采取的操作。Sends changes that were made to retrieved objects to the underlying database, and specifies the action to be taken if the submission fails.

注解

如果存在用于插入、更新或删除的替代方法,则SubmitChanges将执行这些方法,而不LINQ to SQLLINQ to SQL是默认命令。If override methods are present for insert, update, or delete, SubmitChanges executes these methods instead of the default LINQ to SQLLINQ to SQL commands.

SubmitChanges启动事务,并在执行时发生异常时SubmitChanges回滚。SubmitChanges starts a transaction and will roll back if an exception occurs while SubmitChanges is executing. 但是,这不会回滚内存中的更改,也不会对DataContext其进行跟踪; 这些更改将需要手动回滚。However, this does not roll back the changes in memory or tracked by the DataContext; those changes will need to be rolled back manually. 如果要放弃内存中的更改,则DataContext可以从的新实例开始。You can start with a new instance of the DataContext if the changes in memory are to be discarded.

SubmitChanges()

计算要插入、更新或删除的已修改对象的集,并执行相应命令以实现对数据库的更改。Computes the set of modified objects to be inserted, updated, or deleted, and executes the appropriate commands to implement the changes to the database.

public:
 void SubmitChanges();
public void SubmitChanges ();
member this.SubmitChanges : unit -> unit
Public Sub SubmitChanges ()

注解

如果存在用于插入、更新或删除的替代方法,则SubmitChanges将执行这些方法,而不LINQ to SQLLINQ to SQL是默认命令。If override methods are present for insert, update, or delete, SubmitChanges executes these methods instead of the default LINQ to SQLLINQ to SQL commands.

SubmitChanges(ConflictMode)

将对检索到的对象所做的更改发送到基础数据库,并指定提交失败时要采取的操作。Sends changes that were made to retrieved objects to the underlying database, and specifies the action to be taken if the submission fails.

public:
 virtual void SubmitChanges(System::Data::Linq::ConflictMode failureMode);
public virtual void SubmitChanges (System.Data.Linq.ConflictMode failureMode);
abstract member SubmitChanges : System.Data.Linq.ConflictMode -> unit
override this.SubmitChanges : System.Data.Linq.ConflictMode -> unit
Public Overridable Sub SubmitChanges (failureMode As ConflictMode)

参数

failureMode
ConflictMode

提交失败时要采取的操作。The action to be taken if the submission fails. 有效参数包括:Valid arguments are as follows: FailOnFirstConflictContinueOnConflict

示例

Northwnd db = new Northwnd("...");

// Create, update, delete code.

db.SubmitChanges(ConflictMode.FailOnFirstConflict);
// or
db.SubmitChanges(ConflictMode.ContinueOnConflict);
Dim db As New Northwnd("...")

' Create, update, delete code.

db.SubmitChanges(ConflictMode.FailOnFirstConflict)
' or
db.SubmitChanges(ConflictMode.ContinueOnConflict)

注解

默认失败模式为FailOnFirstConflictDefault failure mode is FailOnFirstConflict.

适用于