DataServiceContext.UpdateObject(Object) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
에 있는 지정된 개체의 상태를 변경합니다 DataServiceContextModified.
public:
void UpdateObject(System::Object ^ entity);
public void UpdateObject(object entity);
member this.UpdateObject : obj -> unit
Public Sub UpdateObject (entity As Object)
매개 변수
예외
시기 entity 입니다.null
상태에 있는 경우 entityDetached 입니다.
예제
다음 예제에서는 기존 개체를 검색하고 수정한 다음, 컨텍스트의 항목을 업데이트된 것으로 표시하기 위해 메서드 DataServiceContext 를 호출 UpdateObject 합니다. HTTP MERGE 메시지가 호출되면 데이터 서비스 SaveChanges 로 전송됩니다. 이 예제에서는 WCF Data Services를 완료할 때 만들어지는 Northwind 데이터 서비스를 기반으로 서비스 참조 추가 도구에서 생성한 것을 사용합니다 DataServiceContext .
string customerId = "ALFKI";
// Create the DataServiceContext using the service URI.
NorthwindEntities context = new NorthwindEntities(svcUri);
// Get a customer to modify using the supplied ID.
var customerToChange = (from customer in context.Customers
where customer.CustomerID == customerId
select customer).Single();
// Change some property values.
customerToChange.CompanyName = "Alfreds Futterkiste";
customerToChange.ContactName = "Maria Anders";
customerToChange.ContactTitle = "Sales Representative";
try
{
// Mark the customer as updated.
context.UpdateObject(customerToChange);
// Send the update to the data service.
context.SaveChanges();
}
catch (DataServiceRequestException ex)
{
throw new ApplicationException(
"An error occurred when saving changes.", ex);
}
Dim customerId = "ALFKI"
' Create the DataServiceContext using the service URI.
Dim context = New NorthwindEntities(svcUri)
' Get a customer to modify using the supplied ID.
Dim customerToChange = (From customer In context.Customers
Where customer.CustomerID = customerId
Select customer).Single()
' Change some property values.
customerToChange.CompanyName = "Alfreds Futterkiste"
customerToChange.ContactName = "Maria Anders"
customerToChange.ContactTitle = "Sales Representative"
Try
' Mark the customer as updated.
context.UpdateObject(customerToChange)
' Send the update to the data service.
context.SaveChanges()
Catch ex As DataServiceRequestException
Throw New ApplicationException(
"An error occurred when saving changes.", ex)
End Try