title: Entity Framework - Error on db.SaveChanges()
body: <p>I am using the Entity Framework to create a database and write to it from my model and controller.  I am getting an error on the line "DB.SaveChanges();".  The error states: "An error occurred while updating the entries. See the inner exception for details."  Then the inner exceptions states: "Invalid object name 'dbo.ContactModel'."  I have looked through all the SO posts with a similar question but none seemed to fix my issue.  I will post the code that I think is relevant to the issue.  Let me know if there is more needed.</p>
  
  <p>My ContactContext.cs class:</p>
  
  <pre><code>using newBestPlay.Models;
  using System.Data.Entity;
  using System.Data.Entity.ModelConfiguration.Conventions;
  
  namespace newBestPlay.DAL
  {
      public class ContactContext : DbContext
      {
  
          public ContactContext() : base("BestPlay")
          {
          }
  
          public DbSet&lt;ContactModel&gt; Contacts { get; set; }
  
          protected override void OnModelCreating(DbModelBuilder modelBuilder)
          {
              modelBuilder.Conventions.Remove&lt;PluralizingTableNameConvention&gt;();
          }
      }
  }
  </code></pre>
  
  <p>And my &lt; connectionStrings > in web.config:</p>
  
  <pre><code>&lt;connectionStrings&gt;
  &lt;add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDBFilename=|DataDirectory|\Contacts.mdf;Initial Catalog=Contacts;Integrated Security=True" providerName="System.Data.SqlClient" /&gt;
  &lt;add name="BestPlay" connectionString="Data Source=(LocalDb)\v11.0;Integrated Security=True" providerName="System.Data.SqlClient" /&gt;    
  &lt; /connectionStrings &gt;
  </code></pre>
  
  <p>Here is the index post method in the controller:</p>
  
  <pre><code>// POST: Contact/Index
  // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
  // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
  [HttpPost]
  [ValidateAntiForgeryToken]
  public ActionResult Index([Bind(Include = "ID,name,address,city,state,zip,phone,fax,email,requestType,emailAlerts,message")] ContactModel contactModel)
  {
      if (ModelState.IsValid)
      {
          contactModel.name = ToTitleCase(contactModel.name);
          contactModel.address = ToTitleCase(contactModel.address);
          contactModel.city = ToTitleCase(contactModel.city);
          db.Contacts.Add(contactModel);
          db.SaveChanges();
          TempData["Message"] = "Thank you for your input.  If requested, we will contact you soon.";
          return RedirectToAction("Index");
      }
  
      return View(contactModel);
  }
  </code></pre>
  
  <p>I would think that would be all that is needed.  Let me know if more code is needed.</p>