Listing the customers
The next thing we need to do is to get a list of customers to display in the UI. Our approach will be to create a data provider that will query the entity framework to get our entities, which we will use as our models. To accomplish this, follow these steps:
- Add a project reference from
Northwind.ViewModel
toNorthwind.Data
. - Add a .NET reference to
System.Data.Entity
. - Add
using
statements forSystem.Collections.Generic, Northwind.Data
, andSystem.Data.Objects
toMainWindowViewModel
. - Add the following code to
MainWindowViewModel
:private IList<Customer> _customers; public IList<Customer> Customers { get { if (_customers == null) { GetCustomers(); } return _customers; } } private void GetCustomers() { _customers = new NorthwindEntities() ...
Get MVVM Survival Guide for Enterprise Architectures in Silverlight and WPF now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.