다음을 통해 공유


ChangeOperationResponse 클래스

DataServiceResponse 클래스에서 반환된 작업 응답을 열거할 때 SaveChanges를 호출한 후에 반환되는 결과입니다.

상속 계층

System.Object
  System.Data.Services.Client.OperationResponse
    System.Data.Services.Client.ChangeOperationResponse

네임스페이스:  System.Data.Services.Client
어셈블리:  Microsoft.Data.Services.Client(Microsoft.Data.Services.Client.dll)

구문

‘선언
Public NotInheritable Class ChangeOperationResponse _
    Inherits OperationResponse
‘사용 방법
Dim instance As ChangeOperationResponse
public sealed class ChangeOperationResponse : OperationResponse
public ref class ChangeOperationResponse sealed : public OperationResponse
[<SealedAttribute>]
type ChangeOperationResponse =  
    class
        inherit OperationResponse
    end
public final class ChangeOperationResponse extends OperationResponse

ChangeOperationResponse 유형에서 다음 멤버를 표시합니다.

속성

  이름 설명
공용 속성 Descriptor 변경 작업에 의해 수정된 EntityDescriptor 또는 LinkDescriptor를 가져옵니다.
공용 속성 Error 작업에서 throw된 오류를 가져옵니다. (OperationResponse에서 상속됨)
공용 속성 Headers 파생 클래스에서 재정의된 경우 단일 작업과 연관된 HTTP 응답 헤더를 포함합니다. (OperationResponse에서 상속됨)
공용 속성 StatusCode 파생 클래스에서 재정의된 경우 단일 작업과 연관된 HTTP 응답 코드를 가져오거나 설정합니다. (OperationResponse에서 상속됨)

맨 위로 이동

메서드

  이름 설명
공용 메서드 Equals (Object에서 상속됨)
보호된 메서드 Finalize (Object에서 상속됨)
공용 메서드 GetHashCode (Object에서 상속됨)
공용 메서드 GetType (Object에서 상속됨)
보호된 메서드 MemberwiseClone (Object에서 상속됨)
공용 메서드 ToString (Object에서 상속됨)

맨 위로 이동

주의

ChangeOperationResponse 개체는 이 라이브러리의 사용자가 직접 생성할 수 없습니다. 대신, DataServiceResponse 클래스의 열거자를 통해 반환된 작업 응답을 열거할 때 참조가 반환됩니다.

SaveChangesSaveChanges가 마지막으로 호출된 후 DataServiceContext에서 수집된 보류 중인 변경 내용을 데이터 서비스에 전송합니다. 변경 내용은 AddObject, AddLink, DeleteObject, DeleteLink, Detach, DetachLink 및 유사 메서드를 호출하면 컨텍스트에 추가됩니다.

SaveChanges는 데이터 서비스에 전송된 모든 작업에 대한 응답을 나타내는 DataServiceResponse를 반환합니다. DataServiceResponse 개체는 유지되거나 시도된 변경 내용을 나타내는 EntityDescriptor 또는 LinkDescriptor 인스턴스의 시퀀스가 차례로 포함되는 ChangeOperationResponse 개체의 시퀀스를 포함합니다.

다음 코드에서는 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.
}
}

스레드 보안

이 유형의 모든 공용 static(Visual Basic에서는 Shared) 멤버는 스레드로부터 안전합니다. 인스턴스 멤버는 스레드로부터의 안전성이 보장되지 않습니다.

참고 항목

참조

System.Data.Services.Client 네임스페이스