使用“.TagWithCallSite()”全局标记 EF Core 查询
Globally Tag EF Core Queries with ".TagWithCallSite()"
随着 EF Core 6.0 中 .TagWithCallSite()
方法的发布,我想知道是否有办法以某种方式通过 DbContext
在每个查询 运行 上全局应用此方法?
最好在整个项目中应用它,而不必将它单独放在每个查询上。
不,你不能那样做。
当您显式定义 TagWithCallSite()
时,编译器会自动填充默认参数 filePath
和 lineNumber
。不可能为所有查询定义它,因为编译器不会将此类信息存储在表达式树中。
TagWithCallSite
accepts parameters marked with CallerFilePathAttribute
and CallerLineNumberAttribute
由编译器在构建过程中填写(或手动填写),因此无法全局设置。
随着 EF Core 6.0 中 .TagWithCallSite()
方法的发布,我想知道是否有办法以某种方式通过 DbContext
在每个查询 运行 上全局应用此方法?
最好在整个项目中应用它,而不必将它单独放在每个查询上。
不,你不能那样做。
当您显式定义 TagWithCallSite()
时,编译器会自动填充默认参数 filePath
和 lineNumber
。不可能为所有查询定义它,因为编译器不会将此类信息存储在表达式树中。
TagWithCallSite
accepts parameters marked with CallerFilePathAttribute
and CallerLineNumberAttribute
由编译器在构建过程中填写(或手动填写),因此无法全局设置。