Using the in-memory database of entity framework is super easy. Create an asp.net core and reference the following NuGet package if it's not referenced( it's been referenced in asp.net core 2 and above):
- Microsoft.EntityFrameworkCore.InMemory
Then create the context just like the past:
class SampleDbContext : DbContext
{
public SampleDbContext() { }
public SampleDbContext(DbContextOptions<SampleDbContext> options)
: base(options)
{ }
}
And add the InMemory Configuration in ConfigureService() of startup class:
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddDbContext<SampleDbContext>(context => { context.UseInMemoryDatabase("Sample"); });
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}
Category: Software
Tags: Entity Framework