WCF RIA Services 中 DomainContext 和操作

原文在 http://msdn.microsoft.com/zh-cn/library/ee707370(v=vs.91)

 

 DomainContext 类支持查询、提交和调用这三种域操作.  LoadOperationSubmitOperationInvokeOperation

LoadOperation:

        EntityQuery<Customer> query =
            from c in _customerContext.GetCustomersQuery()
            where c.Phone.StartsWith("583")
            orderby c.LastName
            select c;
        LoadOperation<Customer> loadOp = this._customerContext.Load(query);
        CustomerGrid.ItemsSource = loadOp.Entities;

        也可以:

        LoadOperation<Customer> loadOp =

                     this._customerContext.Load(_customerContext.GetCustomersQuery());
        CustomerGrid.ItemsSource = loadOp.Entities;

        演练:展示 RIA Services 中的例子:

        this.dataGrid1.ItemsSource = _OrganizationContext.Employees; //多了这一行
        _OrganizationContext.Load(_OrganizationContext.GetEmployeesQuery());

 

/**************如果要在客户端调用 通过 InvokeOperation 调用 GetEmployeesQuery, 需要在服务器端的方法添加属性 [Invoke()]

在客户端调用的程序如下所示:

                ctx.GetEmployees(invokeOperation =>
                {
                    if(invokeOperation.HasError)
                    {
                        MessageBox.Show("invokeOperation.HasError");
                    }
                    else
                    {
                        this.dataGrid1.ItemsSource = invokeOperation.Value; //该值可以看成是同步的值了。
                    }
                }, null);


 

posted @ 2012-05-28 17:03  Ken-Cai  阅读(507)  评论(0编辑  收藏  举报