说明:

  System.ServiceModel.DomainServices.Client.LoadOperation - 用于异步加载
  System.ServiceModel.DomainServices.Client.InvokeOperation - 用于异步调用
  System.ServiceModel.DomainServices.Client.SubmitOperation - 用于异步提交

写法一

 private void button3_Click(object sender, RoutedEventArgs e)
        {
              ds.Load(ds.GetSelectAllStudentQuery(), (x) =>
            {
                this.dataGrid1.ItemsSource = x.Entities;
            }, null);
}           

写法二

 

private void button3_Click(object sender, RoutedEventArgs e)
        {
            LoadOperation<SelectAllStudent_Result> loadOperation = ds.Load(ds.GetSelectAllStudentQuery(), OnLoadCallback, false);
        }
private void OnLoadCallback(LoadOperation<SelectAllStudent_Result> loadOp)
        {
            if (loadOp.HasError)
            {
                MessageBox.Show(loadOp.Error.Message);
                loadOp.MarkErrorAsHandled();
            }
            else
            {
                this.dataGrid1.ItemsSource = loadOp.Entities;
            }
        }

写法三

 

private void button3_Click(object sender, RoutedEventArgs e)
        {
EntityQuery<SelectAllStudent_Result> query = ds.GetSelectAllStudentQuery().OrderByDescending(p => p.StudentID);
LoadOperation<SelectAllStudent_Result> lo = ds.Load(query);
            lo.Completed += delegate
            {
                this.dataGrid1.ItemsSource = lo.Entities;
            };
        }

 

 

posted on 2011-12-13 11:15  NNKOOK  阅读(356)  评论(0编辑  收藏  举报