Bagikan melalui


ChangeOperationResponse Kelas

Definisi

Hasil yang dikembalikan setelah panggilan ke SaveChanges() saat menghitung respons operasi yang dikembalikan oleh DataServiceResponse kelas .

public ref class ChangeOperationResponse sealed : System::Data::Services::Client::OperationResponse
public sealed class ChangeOperationResponse : System.Data.Services.Client.OperationResponse
type ChangeOperationResponse = class
    inherit OperationResponse
Public NotInheritable Class ChangeOperationResponse
Inherits OperationResponse
Warisan
ChangeOperationResponse

Contoh

Kode berikut menunjukkan cara memproses hasil panggilan ke SaveChanges.

DataServiceContext service = new DataServiceContext(new Uri("http://myserviceroot"));  

// Do insert, update, delete, or attach operations.  

DataServiceResponse dsr;  

try  
{  
    dsr = service.SaveChanges(SaveChangesOptions.Batch);    
   // Or service.SaveChanges(SaveChangesOptions.ContinueOnError);   
   //Or service.SaveChanges();  
   // If there are no errors during save changes, process the results:  

    if (dsr.IsBatchResponse)  
    {  
           /*inspect HTTP artifacts associated with the entire batch:  
                             dsr.BatchHeaders, dsr.BatchStatusCode*/ }  

    foreach (ChangeOperationResponse cor in dsr)  
    {  

            if (cor.Descriptor is EntityDescriptor)  
            {  
                EntityDescriptor ed = (EntityDescriptor)cor.Descriptor;  
                // This should be the case if  
                // SaveChanges did not throw an exception.    

                // After an entity is processed by SaveChanges,  
                // it is always moved to the unchanged state.  
                System.Diagnostics.Debug.Assert(  
                           ed.State == EntityStates.Unchanged);    
                // This shows that the state should be unchanged if  
                // the result is success.  

                //process the entity in the response payload: ed.Entity  
            }  
            else if (cor.Descriptor is LinkDescriptor)  
            {  
                LinkDescriptor ld = (LinkDescriptor)cor.Descriptor;  
               // This should be the case if SaveChanges did not throw an exception.  

               // After an entity is processed by SaveChanges it  
               // is always moved to the unchanged state.  
                System.Diagnostics.Debug.Assert(  
                            ld.State == EntityStates.Unchanged);    
                // The state should be unchanged if the result is success.  

                //process the link in the response payload: ld.Source,  
                // ld.SourceProperty, or ld.Target.  
            }  
     }  

}  
catch (DataServiceSaveException se)  
{  
    // Error while saving changes  
    dsr = se.Response;  

    if (dsr.IsBatchResponse)   
    {   
        /*inspect HTTP artifacts associated with the entire batch:  
             dsr.BatchHeaders, dsr.BatchStatusCode*/   
}      
}  

    foreach (ChangeOperationResponse cor in dsr)  
    {  
        if (cor.Error != null)  
        {  
            //process error  
        }  
        else  
        {  
            // same success case processing as in the loop over DSRs results in   
            // the try block. You could put that processing in a method   
            // and call it from here.      
        }  
    }  

}  

 catch(Exception)  
 {  
    // Error while saving changes, but not thrown by the client library.  

    // Process ArgumentException, InvalidOperationException, or similar.  
}  
}  

Keterangan

ChangeOperationResponse objek tidak dimaksudkan untuk dibangun langsung oleh pengguna pustaka ini. Sebaliknya, referensi dikembalikan saat menghitung respons operasi yang dikembalikan melalui enumerator pada DataServiceResponse kelas .

SaveChanges mengirimkan perubahan yang tertunda ke layanan data yang DataServiceContext dikumpulkan oleh sejak panggilan terakhir ke SaveChanges. Perubahan ditambahkan ke konteks dengan memanggil AddObject, , AddLink, DeleteObject, DeleteLinkDetach, DetachLink, dan metode serupa.

SaveChangesDataServiceResponse mengembalikan yang mewakili respons terhadap semua operasi yang dikirim ke layanan data. Objek DataServiceResponse mencakup urutan ChangeOperationResponse objek yang, pada gilirannya, berisi urutan EntityDescriptor atau LinkDescriptor instans yang mewakili perubahan yang dipertahankan atau dicoba.

Properti

Descriptor

EntityDescriptor Mendapatkan atau LinkDescriptor dimodifikasi oleh operasi perubahan.

Error

Mendapatkan kesalahan yang dilemparkan oleh operasi.

(Diperoleh dari OperationResponse)
Headers

Saat ditimpa di kelas turunan, berisi header respons HTTP yang terkait dengan satu operasi.

(Diperoleh dari OperationResponse)
StatusCode

Saat ditimpa di kelas turunan, mendapatkan atau mengatur kode respons HTTP yang terkait dengan satu operasi.

(Diperoleh dari OperationResponse)

Metode

Equals(Object)

Menentukan apakah objek yang ditentukan sama dengan objek saat ini.

(Diperoleh dari Object)
GetHashCode()

Berfungsi sebagai fungsi hash default.

(Diperoleh dari Object)
GetType()

Mendapatkan instans Type saat ini.

(Diperoleh dari Object)
MemberwiseClone()

Membuat salinan dangkal dari yang saat ini Object.

(Diperoleh dari Object)
ToString()

Mengembalikan string yang mewakili objek saat ini.

(Diperoleh dari Object)

Berlaku untuk