Entity Framework Core - Required field for connecting to memory

In previous versions of the Entity Framework, I used Effort ( https://effort.codeplex.com/ ) for unit tests. I decided to provide a new memory provider for EF Core and quickly realized that it did not comply with IsRequired () and other object configurations set in OnModelCreating. Is there any way to verify this configuration? If not, is it on the list of tasks to be implemented? Maybe even an alternative in memory?

I would like to be able to use the testing steps to replace the context and use real db in some integration test scenarios that could use the same code. It sounds like “nice to have,” and perhaps this is an example of an effort with EF Core. I could not find anything about the efforts that worked on this for the EF Core.

I could not find anything on the Uservoice page for EF ( https://data.uservoice.com/forums/72025-entity-framework-feature-suggestions ) and will go further if this is simply not available.

+4
source share
1 answer

, . , , , , , - , .

, SQLite , , UseInMemory(): https://docs.microsoft.com/en-us/ef/core/miscellaneous/testing/sqlite

: Microsoft.EntityFrameworkCore.Sqlite, Microsoft.Data.Sqlite, .

, , webapi, , , .. .

:

services.AddDbContext<MyDbContext>(options =>
{
    var liteConn = new SqliteConnection("DataSource=:memory:");
    liteConn.Open();

    options
        .UseSqlite(liteConn)
        .ConfigureWarnings(warnings =>
        {
            warnings.Throw(RelationalEventId.QueryClientEvaluationWarning);
            warnings.Log(RelationalEventId.ExecutedCommand);
        });
});

Configure:

if (env.IsDevelopment())
{
    var context = app.ApplicationServices.GetRequiredService<MyDbContext>();
    context.Database.EnsureCreated();
}
+3

Source: https://habr.com/ru/post/1628410/


All Articles