调试发现执行到这里就会抛出异常,db上下文已被释放
Cannot access a disposed context instance. A common cause of this
error is disposing a context instance that was resolved from
dependency injection and then later trying to use the same context
instance elsewhere in your application. This may occur if you are
calling ‘Dispose’ on the context instance, or wrapping it in a using
statement. If you are using dependency injection, you should let the
dependency injection container take care of disposing context
instances. Object name: 'xxxDbContext
解决方式
方法上添加 [UnitOfWork],方法添加 virtual 修饰符