比如我现在有两个DBContext :DbContextA,DbContextBservices.AddDbContextPool<DbContextA>(options => { //options.UseInMemoryDatabase("adult"); options.UseSqlServer(Configuration.GetConnectionString("AdultDbStr")); }); services.AddDbContextPool<DbContextB>(options => { //options.UseInMemoryDatabase("Identity"); options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")); });
当我激活DbContextA的实例时会说
ArgumentException:
Expression of type Microsoft.EntityFrameworkCore.DbContextOptions [DbContextA]
cannot be used for constructor parameter of type
Microsoft.EntityFrameworkCore.DbContextOptions [DbContextB]
当我将DbContextPool换成DbContext就没有问题了。
我尝试过将注入顺序调换,结果是用DbContextPool只会记住最后一个注入的,前边的都是被覆盖掉。
请问这是为什么?
环境:.Net Core 2.1 RC1
aluckdog