コード例 #1
0
        private void saveButton_Click(object sender, RoutedEventArgs e)
        {
            // Find the object to update from local list.
            ApressODataService.ApressBook selectedBook = bookListFromService.First(Book => Book.ApressBookISBN == "978-1-4302-3816-4");

            // Make local changes.
            selectedBook.ApressBookAuthor = "Samidip Basu";

            // Mark the object dirty & ready for update to DB.
            oDataContext.UpdateObject(selectedBook);

            // Commit all at once.
            oDataContext.BeginSaveChanges(new AsyncCallback(SaveDoneCallBack), null);
        }
コード例 #2
0
        public void UpdateObjectWithoutChange()
        {
            int expectedPropertyCount = 0;

            this.TestClientContext.Configurations.RequestPipeline.OnEntryEnding(
                (arg) =>
            {
                if (arg.Entry.TypeName.EndsWith("Company"))
                {
                    Assert.AreEqual(expectedPropertyCount, arg.Entry.Properties.Count());
                }
            });

            DataServiceCollection <CompanyPlus> publicCompany =
                new DataServiceCollection <CompanyPlus>(this.TestClientContext.PublicCompanyPlus);

            DataServiceCollection <AccountPlus> account =
                new DataServiceCollection <AccountPlus>(this.TestClientContext.AccountsPlus);

            // Update object by update object without change => redo the PATCH all
            this.TestClientContext.UpdateObject(publicCompany.Single());
            //Properties only defnied by customer will also be sent.
            expectedPropertyCount = 5;
            this.TestClientContext.SaveChanges();

            publicCompany.Single().RevenuePlus = 200;
            expectedPropertyCount = 1;
            this.TestClientContext.SaveChanges();

            // Update object which contains open complex type
            this.TestClientContext.UpdateObject(account.First());
            //Properties only defnied by customer will also be sent.
            expectedPropertyCount = 3;
            this.TestClientContext.Configurations.RequestPipeline.OnEntryEnding(
                (arg) =>
            {
                if (arg.Entry.TypeName.EndsWith("AccountInfo"))
                {
                    Assert.AreEqual(4, arg.Entry.Properties.Count());
                }
            });
            this.TestClientContext.SaveChanges();
        }