Duration (Pacific Standard Time):
To (Pacific Standard Time):
Impact:
  • None
User Action:
  • None
.NET Framework Class Library

DataContext.GetChangeSet Method

Gets the modified objects tracked by DataContext.

Namespace:  System.Data.Linq
Assembly:  System.Data.Linq (in System.Data.Linq.dll)
Public Function GetChangeSet As ChangeSet

Return Value

Type: System.Data.Linq.ChangeSet
The set of objects is returned as three read-only collections.

Note the following considerations:

  • GetChangeSet might have side effects, such as inference of insert and delete operations that are usually performed at the time of SubmitChanges. For example, objects that are used in the following operations can create corresponding inferred operations in the following list:

  • The set may not be ordered according to foreign key constraints.

  • Database-generated values (for example, primary and foreign key values, timestamps, and so forth) are not available. Such information requires database command execution and perhaps the propagation of retrieved information (for example, foreign key from primary key).

  • The set of changed objects is computed at the time of the call. Subsequent calls to SubmitChanges can produce a different set if additional changes are made.

Output when no changes have been made appears as follows:

{Added: 0, Removed: 0, Modified: 0}

Dim db As New Northwnd("c:\northwnd.mdf")

Dim custQuery = _
    From cust In db.Customers _
    Where (cust.City = "London") _
    Select cust

For Each custObj As Customer In custQuery
    Console.WriteLine("CustomerID: {0}", custObj.CustomerID)
    Console.WriteLine(vbTab & "Original value: {0}", custObj.City)
    custObj.City = "Paris"
    Console.WriteLine(vbTab & "Updated value: {0}", custObj.City)
Next 

Dim cs As ChangeSet = db.GetChangeSet()
Console.Write("Total changes: {0}", cs)
' Freeze the console window.
Console.ReadLine()

db.SubmitChanges()

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5

.NET Framework Client Profile

Supported in: 4

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.