title: How to map exisiting sql server view with EF code first
body: <p>i am fairly new in EF and learning EF code first. i am looking for a knowledge to map exisiting sql server view with EF code first. i have map my view with POCO but getting the below error.</p>
  
  <p>when i try to fetch data from view then got the below error thrown</p>
  
  <blockquote>
    <p>Additional information: The model backing the 'TestDBContext' context
    has changed since the database was created. Consider using Code First
    Migrations to update the database</p>
  </blockquote>
  
  <h2>my full code as follow</h2>
  
  <pre><code>public class TestDBContext : DbContext
      {
          public TestDBContext()
              : base("name=TestDBContext")
          {
          }
  
          protected override void OnModelCreating(DbModelBuilder modelBuilder)
          {
              modelBuilder.Configurations.Add(new vwCustomerConfiguration());
          }
  
          public DbSet&lt;vwCustomer&gt; vwCustomer { get; set; }
      }
  
  public class vwCustomerConfiguration : EntityTypeConfiguration&lt;vwCustomer&gt;
  {
      public vwCustomerConfiguration()
      {
          this.HasKey(t =&gt; t.CustomerID);
          this.ToTable("vwCustomer");
      }
  }
  
        public class vwCustomer
          {
              public int CustomerID { get; set; }
              public string FirstName { get; set; }
  
          }
  </code></pre>
  
  <h2>this way i am trying to load data.</h2>
  
  <pre><code>    using (var db = new TestDBContext())
      {
          var listMyViews = db.vwCustomer.ToList();
      }
  </code></pre>
  
  <p>guide me what i am missing in code for which error is throwing. thanks</p>
  
  <h2>UPDATE1</h2>
  
  <p>When i issue Add-Migration "My_vwCustomer" then i saw new migration code added as below one. it seems there is no migration is pending.</p>
  
  <pre><code>   public partial class My_vwCustomer : DbMigration
      {
          public override void Up()
          {
              CreateTable(
                  "dbo.vwCustomers",
                  c =&gt; new
                      {
                          CustomerID = c.Int(nullable: false, identity: true),
                          FirstName = c.String(),
                      })
                  .PrimaryKey(t =&gt; t.CustomerID);
  
          }
  
          public override void Down()
          {
              DropTable("dbo.vwCustomers");
          }
      }
  </code></pre>