title: Entity Framework Core 2 - Code first not creating tables
body: <p>Entity Framework Core 2.0 has been <a href="https://blogs.msdn.microsoft.com/dotnet/2017/08/14/announcing-entity-framework-core-2-0/" rel="noreferrer">recently released</a> and i am using it.</p>
  
  <p>I have added the following line in method ConfigurationServices() in file Startup.cs (My connectionstring is fine).</p>
  
  <pre><code>services.AddDbContext&lt;AutoPartsContext&gt;(options =&gt; 
  options.UseSqlServer(Configuration.GetConnectionString("NetCore")));
  </code></pre>
  
  <p>and in Configure method, </p>
  
  <pre><code>using (var serviceScope = 
  app.ApplicationServices.GetService&lt;IServiceScopeFactory&gt;().CreateScope())
  {
  var context = 
  serviceScope.ServiceProvider.GetRequiredService&lt;MyConntectionStringName&gt;();
  context.Database.Migrate();
  context.Database.EnsureCreated();
  }
  </code></pre>
  
  <p>This is creating the database but not tables. When i call a simple count on my tables,</p>
  
  <pre><code>var a = _context.Users.Count();
  </code></pre>
  
  <p>It throws following exception</p>
  
  <blockquote>
    <p>Invalid object name 'Users'.
    at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)</p>
  </blockquote>
  
  <p>However, if i create table manually, everything works perfectly. I need all tables to be auto created.</p>
  
  <p>EF Core version: 2.0, Database Provider: Microsoft.EntityFrameworkCore.SqlServer, Operating system: Windows 10, IDE: Visual Studio 2017 Preview 2</p>