title: How to get data from database with Entity Framework?
body: <p>Using c#, net.4.5 vs 2012</p>
  
  <p>I'm trying to get data from database using Entity Framework.</p>
  
  <p>At first idea was use code like below - it's must allow to add, delete and update entries in dataGridView, and than just save changes using <code>context.SaveChanges()</code> (method from <code>ObjectSet</code>, if I'm not wrong)</p>
  
  <pre><code>using (LibraryEntities context = new LibraryEntities())
  {
              var query = (from c in context.Book select c).First();
              DataGridView dgv = new DataGridView();
              dgv.DataSource = context.Book;
  }
  </code></pre>
  
  <p>Result - exception </p>
  
  <blockquote>
    <p>Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is not supported...</p>
  </blockquote>
  
  <p>Then I try a little bit changed code:</p>
  
  <pre><code>using (LibraryEntities context = new LibraryEntities())
  {
      var query = (from c in context.Book select c).First();
      DataGridView dgv = new DataGridView();
      dgv.DataSource = query;
  }
  </code></pre>
  
  <p>but have same issue with exception </p>
  
  <blockquote>
    <p>Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is not supported...</p>
  </blockquote>
  
  <p>At last try to convert all to <code>List()</code>:</p>
  
  <pre><code>using (LibraryLib.LibraryEntities context = new LibraryLib.LibraryEntities())
  {
      DataGridView dgv = new DataGridView();
      dgv.DataSource = (from c in context.Book select c).ToList();
  }
  </code></pre>
  
  <p>As and expected, I got all db entries in DataGridView, but I can't add, update and delete any entries.</p>
  
  <p><img src="https://i.stack.imgur.com/SDAm1.png" alt="enter image description here"></p>
  
  <p>And the question is - how can I change db in <code>dataGridView</code> and than save it with <code>DbContext.SaveChanges()</code></p>