我遇到了一个插件正在查询和获取一些数据的情况,我无法将插件中的查询更改为DLL。我已经使用SQL事件探查器检查了它正在执行的查询,并且根据我们的要求,我们已经更改了该区域中的数据库架构,因此破坏了该插件查询。
有没有办法拦截查询并对其进行更改?
就像我们在Angular这样的JS框架中所做的一样,我们有拦截器来接收每个调用并在标头中添加令牌,我们是否有类似的功能来拦截所有传出的SQL调用并对其进行更改?
也许中间件可以像我在.NET-Core或某种处理程序中一样在这里工作?
查询可以在拦截器中更改,例如
class EFCommandInterceptor: IDbCommandInterceptor
{
public void NonQueryExecuting(System.Data.Common.DbCommand command, DbCommandInterceptionContext<int> interceptionContext)
{
// Change here
}
注册:
public class FE6CodeConfig : DbConfiguration
{
public FE6CodeConfig()
{
this.AddInterceptor(new EFCommandInterceptor());
}
}
在此处查看更多详细信息https://www.entityframeworktutorial.net/entityframework6/database-command-interception.aspx
PS:如今,EF内核也有拦截器。 https://docs.microsoft.com/en-us/ef/core/what-is-new/ef-core-3.0/#interception-of-database-operations