开发者

RIA: how to intercept the data

On the clien side I have the following assignement of objects list to a datagrid:

        var customerContext = new RiaTestCustomDomainContext();
        Cust开发者_JS百科omerGrid.ItemsSource = customerContext.Customers;
        customerContext.Load(customerContext.GetCustomersQuery());

It works good, but I woudl like to have the same list of objects in a separate collection and use it for other objects population.

When I tried to push customerContext.Customers into List I've got an error:

Cannot implicitly convert type 'System.Windows.Ria.EntitySet' to 'System.Collections.ObjectModel.ObservableCollection'

Here is a code that I've tried to compile:

        var customerContext = new RiaTestCustomDomainContext();
        ObservableCollection<Customer> customers = customerContext.Customers;

Could you please advise how can I achieve data into List<> collection?

Thanks.


Assuming you are working in the code behind or a view model attached to your presentation XAML.

Ensure that System.Linq is in your usings list.

public class XXX
{
  private CustomerContext _context;

  private List<Customer> _customers;

  public XXX()
  {
    _customers = new List<Customer>();
    LoadData();
  }

  public void LoadData()
  {
    LoadOperation<Customer> loader = _context.Load<Customer>( _context.GetCustomerQuery() );
    loader.Completed += (s,e) =>
      {
        _customers = (s as LoadOperation<Customer>).Entities.ToList();
      };
  }
}

Remember you are starting a async request with the CustomerContext. The Completed event will return subsequently with (hopefully) your customers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜