1

I need to create a database in ASP.NET Core and use identity, and I need to use UseInMemoryDatabase but when I try to add a migration, I get this error:

Unable to create an object of type 'DortajContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728

This is my start up:

 public void ConfigureServices(IServiceCollection services)
    {
        services.AddDbContextPool<DortajContext>(options => options.UseInMemoryDatabase(databaseName: "DortajDistance"));
        services.AddIdentity<IdentityUser, IdentityRole>().AddEntityFrameworkStores<DortajContext>();
        services.AddControllers();
    }

and this is my context :

 public class DortajContext : IdentityDbContext<User, Role, int>
{
    public DortajContext(DbContextOptions<DortajContext> options)
  : base(options)
    {
    }

    public DbSet<UserDistanceHistory> UserDistanceHistories { get; set; }
    protected override void OnModelCreating(ModelBuilder builder)
    {
        base.OnModelCreating(builder);
        builder.ApplyConfigurationsFromAssembly(typeof(IType).Assembly);
    }
}

How can I solve this problem?

1 Answer 1

1

Why do you need migrations for in-memory database?

Migrations are used to versioning database. It is useful when you have a database in production, you changed smth and you can update it with migrations. There is no need to use it for in-memory databases. You can read more about migrations here.

Anyway, InMemory provider was designed only for unit and integration testing. If you want to use in-memory in developing and production, you should use SQLite. Here is issue oh the github

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.