views:

45

answers:

1

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

        var customerContext = new RiaTestCustomDomainContext();
        CustomerGrid.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.

+1  A: 

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.

Rus