本文整理汇总了C#中System.Data.Services.Client.DataServiceContext.UpdateObject方法的典型用法代码示例。如果您正苦于以下问题:C# DataServiceContext.UpdateObject方法的具体用法?C# DataServiceContext.UpdateObject怎么用?C# DataServiceContext.UpdateObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.Services.Client.DataServiceContext
的用法示例。
在下文中一共展示了DataServiceContext.UpdateObject方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NorthwindEntities
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);
}