The DbContext of type cannot be pooled because it does not have a single public constructor accepting a single parameter of type DbContextOptions

前端 未结 5 633
青春惊慌失措
青春惊慌失措 2020-12-08 11:36

I am trying to upgrade our current .Net Core application from 1.1 to 2.0 and am getting this runtime error: \"The DbContext of type \'CoreContext\' cannot be pooled because

5条回答
  •  [愿得一人]
    2020-12-08 12:04

    This issue is mostly encountered when you "Scaffold-Dbcontext" and two constructors are generated.

    Simple Solutions:

    1. AddDbContextPool: If you want to use AddDbContextPool, remove your empty constructor and maintain the one with the DbContextOptionsBuilder. Note that in this case you might have to provide the options, as suggested in the previous posts.

    2. AddDbContext: With AddDbContext, you can have both constructors/Overloads

    Note: AddDbContextPool is preferred for performance reasons!

提交回复
热议问题