DataContext.GetChangeSet Metodo

Definizione

Ottiene gli oggetti modificati monitorati mediante DataContext.

public:
 System::Data::Linq::ChangeSet ^ GetChangeSet();
public System.Data.Linq.ChangeSet GetChangeSet ();
member this.GetChangeSet : unit -> System.Data.Linq.ChangeSet
Public Function GetChangeSet () As ChangeSet

Restituisce

Il set di oggetti viene restituito come tre raccolte di sola lettura.

Esempio

Northwnd db = new Northwnd(@"c:\northwnd.mdf");

var custQuery =
    from cust in db.Customers
    where cust.City == "London"
    select cust;

foreach (Customer custObj in custQuery)
{
    Console.WriteLine("CustomerID: {0}", custObj.CustomerID);
    Console.WriteLine("\tOriginal value: {0}", custObj.City);
    custObj.City = "Paris";
    Console.WriteLine("\tUpdated value: {0}", custObj.City);
}

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

db.SubmitChanges();
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()

Commenti

Tenere presenti le seguenti considerazioni:

  • GetChangeSet potrebbe avere effetti collaterali, ad esempio l'inferenza di operazioni di inserimento ed eliminazione che vengono in genere eseguite al momento di SubmitChanges. Ad esempio, gli oggetti usati nelle operazioni seguenti possono creare operazioni derivate corrispondenti nell'elenco seguente:

  • Il set potrebbe non essere ordinato in base ai vincoli di chiave esterna.

  • I valori generati dal database (ad esempio, valori di chiave primaria ed esterna, timestamp e così via) non sono disponibili. Queste informazioni richiedono l'esecuzione dei comandi del database e forse la propagazione di informazioni recuperate (ad esempio, chiave esterna dalla chiave primaria).

  • Il set di oggetti modificati viene calcolato al momento della chiamata. Le chiamate successive a SubmitChanges possono produrre un set diverso se vengono apportate modifiche aggiuntive.

L'output quando non sono state apportate modifiche viene visualizzato come segue:

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

Si applica a