title: Entity Framework. Get all objects from table and print to the console
body: <p>I am new to EF and im having some serious problems understanding the concept. I have a connection to database and it seems to work. I can add objects. Could some kind soul help me out with retrieving the whole table and then print it to the console.</p>
  
  <p>This is how it looks right now;</p>
  
  <pre><code>namespace EntityFrameWorkExample
  {
  class Program
  {
      static void Main(string[] args)
      {
  
          SampleDBEntities3 samp = new SampleDBEntities3();
          Cars c = new Cars();
          c.Brand = "Ford";
          c.Model = "P200";
          samp.Cars.Add(c);
          samp.SaveChanges();
  
  
          using (var db = new SampleDBEntities3())
          {
  
          }
      }
  }
  }
  
  
  namespace EntityFrameWorkExample
   {
  using System;
  using System.Collections.Generic;
  
  public partial class Cars
  {
      public int CarID { get; set; }
      public string Brand { get; set; }
      public string Model { get; set; }
  
  
  }
  }
  
   namespace EntityFrameWorkExample
   {
  using System;
  using System.Data.Entity;
  using System.Data.Entity.Infrastructure;
  
  public partial class SampleDBEntities3 : DbContext
  {
      public SampleDBEntities3()
          : base("name=SampleDBEntities3")
      {
      }
  
      protected override void OnModelCreating(DbModelBuilder modelBuilder)
      {
          throw new UnintentionalCodeFirstException();
      }
  
      public virtual DbSet&lt;Cars&gt; Cars { get; set; }
  }
  }
  </code></pre>
  
  <p>Thanks in advance!</p>