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.

備註

如果 insert、update 或 delete 有覆寫方法,會執行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 ()

備註

如果 insert、update 或 delete 有覆寫方法,會執行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.

適用於