title: MVVM and DBContext - how to put it together?
body: <p>I'm trying to follow the MVVM pattern, however I spent some good time on this issue, googled a lot and checked stackoverflow as well... No working example found so far. </p>
  
  <p>Basically, I've a simple application and want to retrieve and write data to SQL server. Here's my code:</p>
  
  <p>//Model</p>
  
  <pre><code>public class Visitor
  {
      public string ID { get; set; }
  
  
      public string FirstName { get; set; }
  
      public string LastName { get; set; }
  }
  </code></pre>
  
  <p>//ViewModel</p>
  
  <pre><code>public class VisitorViewModel : ViewModelBase
  {
      public ObservableCollection&lt;Visitor&gt; _visitorDataCollection = new ObservableCollection&lt;Visitor&gt;();
  
      public ObservableCollection&lt;Visitor&gt; VisitorDataCollection
      {
          get { return _visitorDataCollection; }
          set { _visitorDataCollection = value; }
      }
  
      private string _firstName = "";
      private string _lastName = "";
  
  
  
      public string FirstName
      {
          get { return _firstName; }
          set
          {
              if (value != _firstName)
              {
                  _firstName = value;
                  OnPropertyChanged("FirstName");
              }
          }
      }
  
      public string LastName
      {
          get { return _lastName; }
          set
          {
              if (value != _lastName)
              {
                  _lastName = value; 
                  OnPropertyChanged("LastName");
              }
          }
      }
  
      public VisitorViewModel()
      {
  
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>//VisitorContext class that represents a database context</p>
  
  <pre><code>public partial class VisitorContext : DbContext
  {
      public VisitorContext()
          : base()
      {
      }
  
      public DbSet&lt;VISITOR&gt; Visitors { get; set; }
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Nothing really fancy. However, I cannot put it "together". How to complete that to retrieve all visitors and add a new one? </p>
  
  <p>Could someone point me to the right direction?</p>