Пример #1
0
        /// <summary>
        /// Callback method of the delete operation.
        /// </summary>
        /// <param name="result"></param>
        private void OnChangesSaved(IAsyncResult result)
        {
            Dispatcher.BeginInvoke(() =>
            {
                SchoolLinqToSQLDataContext svcContext = result.AsyncState as SchoolLinqToSQLDataContext;

                try
                {
                    // Complete the save changes operation and display the response.
                    WriteOperationResponse(svcContext.EndSaveChanges(result));
                }
                catch (DataServiceRequestException ex)
                {
                    // Display the error from the response.
                    WriteOperationResponse(ex.Response);
                }
                catch (InvalidOperationException ex)
                {
                    messageTextBlock.Text = ex.Message;
                }
                finally
                {
                    // Reload the binding collection to refresh Grid to see if it's successfully updated.
                    // You can also remove the following line. To see the update effect, just refresh the page or check out database directly.
                    LoadData();
                }
            });
        }
Пример #2
0
        /// <summary>
        /// 删除操作的回调事件。
        /// </summary>
        /// <param name="result"></param>
        private void OnChangesSaved(IAsyncResult result)
        {
            Dispatcher.BeginInvoke(() =>
            {
                SchoolLinqToSQLDataContext svcContext = result.AsyncState as SchoolLinqToSQLDataContext;

                try
                {
                    // 完成保存改变操作并显示结果。
                    WriteOperationResponse(svcContext.EndSaveChanges(result));
                }
                catch (DataServiceRequestException ex)
                {
                    // 显示错误信息。
                    WriteOperationResponse(ex.Response);
                }
                catch (InvalidOperationException ex)
                {
                    messageTextBlock.Text = ex.Message;
                }
                finally
                {
                    // 重新加载绑定的集合来刷新Grid,显示操作的结果。
                    // 你也可以删除下边的代码行,并通过刷新本页或者直接查看数据库来看操作结果。
                    LoadData();
                }
            });
        }
Пример #3
0
        /// <summary>
        /// In this method we send a REST request to ADO.NET Data Service to request CourseGrade
        /// records. We expand Person and Course so the foreign records will be returned as well
        /// </summary>
        private void LoadData()
        {
            _context = new SchoolLinqToSQLDataContext(new Uri(_schoolLinqToSQLUri));
            DataServiceQuery <CourseGrade> query = (DataServiceQuery <CourseGrade>)(
                from c in _context.CourseGrades.Expand("Person").Expand("Course")
                select c);

            query.BeginExecute(OnCourseGradeQueryComplete, query);
        }