Search code examples
c#entity-frameworkasp.net-identity-2

inheriting from IdentityDbContext<T> slows down tests


I had a run of the mill dbcontext I was using then I started to implement .net Identity (Microsoft.AspNet.Identity.Core, Microsoft.AspNet.Identity.EntityFramework) and thought "oh look, its based on dbcontext, I'll just attach that to my existing context".

So this ...

public class SomeContext : DbContext {
    public SomeContext() : base("DefaultConnection"){ }
}

Simply turned to this ...

public class SomeContext : IdentityDbContext<ApplicationUser> {
    public SomeContext() : base("DefaultConnection") {}
}

All fine and good, the site runs perfectly with no problems at all... but the tests go from about 1 second to about 2 minutes. If I switch it back it goes right back to the short test runs so I'm thinking I might be missing something or there's something else going on I'm not entirely aware of.

Any ideas?


Solution

  • Change public SomeContext() : base("DefaultConnection") {} to public SomeContext() : base("DefaultConnection", false) {}

    This additional boolean will make IdentityDbContext<ApplicationUser> not check the connection for the identity tables. That will speed up the tests.