I have added the following line in method ConfigurationServices() in file Startup.cs (My connectionstring is fine).
```c#
services.AddDbContext
and in Configure method,
```c#
using (var serviceScope = app.ApplicationServices.GetService<IServiceScopeFactory>().CreateScope())
{
var context = serviceScope.ServiceProvider.GetRequiredService<MyConntectionStringName>();
context.Database.Migrate();
context.Database.EnsureCreated();
}
This is creating the database but not tables. When i call a simple count on my tables,
```c#
var a = _context.Users.Count();
It throws following exception
Exception message: "Invalid object name 'Users'."
Stack trace: at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
```
EF Core version: 2.0
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10
IDE: Visual Studio 2017 Preview 2
@mohsin91 A few things:
Migrate()
is the way to problematically apply migrations that have already been created. It relies on tooling being used to create the migrations. See https://docs.microsoft.com/en-us/ef/core/get-started/aspnetcore/new-db for more details@ajcvickers EnsureCreated does not create the tables for me in the unit tests. How exactly is this supposed to work?
@DominikDitoIvosevic If it's not working, then please open a new issue and include a small, runnable project/solution or complete code listing that demonstrates the behavior you are seeing.
Most helpful comment
@mohsin91 A few things:
Migrate()
is the way to problematically apply migrations that have already been created. It relies on tooling being used to create the migrations. See https://docs.microsoft.com/en-us/ef/core/get-started/aspnetcore/new-db for more details