jxycms
5/21/2018 - 6:13 AM

set up EF InMemory Database

1. Install package Microsoft.EntityFrameworkCore.InMemory

2. In Startup.cs, add

private IHostingEnvironment CurrentEnvironment { get; }

3. In Startup construction method, add

CurrentEnvironment = env;

4. In ConfigureServices method, add

if (CurrentEnvironment.IsDevelopment())
{
    services.AddDbContext<AppDbContext>(
        options => options.UseInMemoryDatabase());
}
else
{
    services.AddDbContext<AppDbContext>(
                    options => options.UseSqlServer(
                        Configuration.GetConnectionString("DefaultConnection")));
}