title: EF Code First from Database - Already an object in the database
body: <p>I created a new .NET project and added ADO.NET EF 6.<br>
  I went through the EF wizard and choose Code First from Database.<br>
  Then I selected a table. Let's call it "Product".<br>
  This created "public partial class Product" and "public partial class Model1".  </p>
  
  <p>I immediately created a LINQ query in my application to query the "Product" but I get the following error.</p>
  
  <blockquote>
    <p>There is already an object named 'Product' in the database.</p>
  </blockquote>
  
  <p>When I run SQL Profile I see the following:</p>
  
  <blockquote>
    <p>CREATE TABLE [dbo].[Product] ...  </p>
  </blockquote>
  
  <p>I don't understand why the project is trying to create the table since the table already exists.  </p>
  
  <p>I read a couple of articles telling me I need to enable migrations but I really don't want my project to be able to create tables in the database.<br>
  (We have a DBA that does not give us access to create tables "easily" in the database)  </p>
  
  <p>I then decided to try creating a "Migrations" folder and a "internal sealed class Configuration" with the following:  </p>
  
  <pre><code>public Configuration()
  {
      AutomaticMigrationsEnabled = false;
      AutomaticMigrationDataLossAllowed = false;
  }
  </code></pre>
  
  <p>This gives me a new error.</p>
  
  <blockquote>
    <p>Unable to update database to match the current model because there are
    pending changes  and automatic migration is disabled. Either write the
    pending model changes to a code-based migration or enable automatic
    migration. Set DbMigrationsConfiguration.AutomaticMigrationsEnabled to
    true to enable automatic migration.</p>
  </blockquote>
  
  <p>How to I fix this? </p>
  
  <p><strong>UPDATE</strong><br>
  So I created both a VB.NET and a C# application with the exact same code pointing against the same database.<br>
  The C# version has the "already in database" issue.<br>
  The VB.NET version does not have the "already in database" issue.</p>