Wrapper around the EF Core In-Memory DB to work around some qwerks
Provides a wrapper around the EF Core In-Memory Database Provider. Specifically works around the following EF bugs.
[Timestamp]
, and .Property(p => p.X).IsRowVersion()
)This project is supported by the community via Patreon sponsorship. If you are using this project to deliver business value or build commercial software it is expected that you will provide support via Patreon.
https://nuget.org/packages/EfCore.InMemoryHelpers/
PM> Install-Package EfCore.InMemoryHelpers
The main entry point is InMemoryContextBuilder
which can be used to build an in-memory context.
using (var context = InMemoryContextBuilder.Build<MyDataContext>())
{
var entity = new MyEntity
{
Property = "prop"
};
context.Add(entity);
context.SaveChanges();
}
A custom DbContextOptionsBuilder
can be passed in:
var builder = new DbContextOptionsBuilder<MyDataContext>();
using (var context = InMemoryContextBuilder.Build<MyDataContext>(builder))
{
var entity = new MyEntity
{
Property = "prop"
};
context.Add(entity);
context.SaveChanges();
}
Both the above usages assume that the target context has a public constructor that accepts a DbContextOptions
.
public MyDataContext(DbContextOptions options)
:
base(options)
{ }
If this is not the case a custom context constructor can be passed in:
var builder = new DbContextOptionsBuilder<MyDataContext>();
using (var context = InMemoryContextBuilder.Build(builder, options => new MyDataContext(options)))
{
var entity = new MyEntity
{
Property = "prop"
};
context.Add(entity);
context.SaveChanges();
}
memory designed by Montu Yadav from The Noun Project