title: WPF MVVM Pattern, ViewModel DataContext question
body: <p>I used this side to create my demo application
  <a href="http://windowsclient.net/learn/video.aspx?v=314683" rel="nofollow noreferrer">http://windowsclient.net/learn/video.aspx?v=314683</a></p>
  
  <p>The site was very useful in getting my started and in their example, they created a file called EmployeeRepository.cs which appears to be the source for the data. In their example, the data was hard-wired in code. So I'm trying to learn how to get the data from a data source (like a DB). In my specific case, I want to get the data from a Microsoft Access DB. (READ ONLY, So I'll only use SELECT commands).</p>
  
  <pre><code>using System.Collections.Generic;
  using Telephone_Directory_2010.Model;
  
  namespace Telephone_Directory_2010.DataAccess
  {
      public class EmployeeRepository
      {
          readonly List&lt;Employee&gt; _employees;
  
          public EmployeeRepository()
          {
              if (_employees == null)
              {
                  _employees = new List&lt;Employee&gt;();
              }
              _employees.Add(Employee.CreateEmployee("Student One", "IT201", "Information Technology", "IT4207", "Building1", "Room650"));
              _employees.Add(Employee.CreateEmployee("Student Two", "IT201", "Information Technology", "IT4207", "Building1", "Room650"));
              _employees.Add(Employee.CreateEmployee("Student Three", "IT201", "Information Technology", "IT4207", "Building1", "Room650"));
          }
  
          public List&lt;Employee&gt; GetEmployees()
          {
              return new List&lt;Employee&gt;(_employees);
          }
      }
  }
  </code></pre>
  
  <p>I found another example where an Access DB is used but it doesn't comply with MVVM. So I was trying to figure out how to add the DB file to the project, how to wire it up and bind it to a listbox (i'm not that far yet). Below is my modified file  </p>
  
  <pre><code>using System.Collections.Generic;
  using Telephone_Directory_2010.Model;
  // integrating new code with working code
  using Telephone_Directory_2010.telephone2010DataSetTableAdapters;
  using System.Windows.Data;
  
  namespace Telephone_Directory_2010.DataAccess
  {
      public class EmployeeRepository
      {
          readonly List&lt;Employee&gt; _employees;
  
          // start
          // integrating new code with working code
          private telephone2010DataSet.telephone2010DataTable employeeTable;
          private CollectionView dataView;
          internal CollectionView DataView
          {
              get
              {
                  if (dataView == null)
                  {
                      dataView = (CollectionView) CollectionViewSource.GetDefaultView(this.DataContext);
                  }
                  return dataView;
              }
          }
  
          public EmployeeRepository()
          {
              if (_employees == null)
              {
                  _employees = new List&lt;Employee&gt;();
              }
              telephone2010TableAdapter employeeTableAdapter = new telephone2010TableAdapter();
              employeeTable = employeeTableAdapter.GetData();
              this.DataContext = employeeTable;
          }
  
          public List&lt;Employee&gt; GetEmployees()
          {
              return new List&lt;Employee&gt;(_employees);
          }
      }
  </code></pre>
  
  <p>}</p>
  
  <p>I get the following error messages when building</p>
  
  <blockquote>
    <p>Error 1   'Telephone_Directory_2010.DataAccess.EmployeeRepository' does not contain a definition for 'DataContext' and no extension method 'DataContext' accepting a first argument of type 'Telephone_Directory_2010.DataAccess.EmployeeRepository' could be found (are you missing a using directive or an assembly reference?) C:\Projects\VS2010\Telephone Directory 2010\Telephone Directory 2010\DataAccess\EmployeeRepository.cs   23  90  Telephone Directory 2010</p>
  </blockquote>