当前位置: 首页 > news >正文

上海网站开发哪家好薇黑龙江建设网首页

上海网站开发哪家好薇,黑龙江建设网首页,网站开发的技术流程,谷歌paypal官网登录入口给 EF Core 查询增加 With NoLockIntroEF Core 在 3.x 版本中增加了 Interceptor#xff0c;使得我们可以在发生低级别数据库操作时作为 EF Core 正常运行的一部分自动调用它们。例如#xff0c;打开连接、提交事务或执行命令时。所以我们可以自定义一个 Interceptor 来记录执… 给 EF Core 查询增加 With NoLockIntroEF Core 在 3.x 版本中增加了 Interceptor使得我们可以在发生低级别数据库操作时作为 EF Core 正常运行的一部分自动调用它们。例如打开连接、提交事务或执行命令时。所以我们可以自定义一个 Interceptor 来记录执行的 sql 语句也可以通过 Interceptor 来实现 sql 语句的执行。这里我们可以借助 Interceptor 实现对于查询语句的修改自动给查询语句加 (WITH NOLOCK) WITH NOLOCK 等效于 READ UNCOMMITED读未提交的事务级别这样会造成一定的脏读但是从效率上而言是比较高效的不会因为别的事务长时间未提交而导致查询阻塞所以对于大数据场景下查询 SQL 加 NOLOCK 还是比较有意义的NoLockInterceptor继承 DbCommandInterceptor重写查询 sql 执行之前的操作在执行 sql 之前增加 WITH(NOLOCK)实现代码如下public class QueryWithNoLockDbCommandInterceptor : DbCommandInterceptor {private static readonly Regex TableAliasRegex new Regex((?tableAliasAS \[[a-zA-Z]\w*\](?! WITH \(NOLOCK\))),RegexOptions.Multiline | RegexOptions.Compiled | RegexOptions.IgnoreCase);public override InterceptionResultobject ScalarExecuting(DbCommand command, CommandEventData eventData, InterceptionResultobject result){command.CommandText TableAliasRegex.Replace(command.CommandText,${tableAlias} WITH (NOLOCK));return base.ScalarExecuting(command, eventData, result);}public override TaskInterceptionResultobject ScalarExecutingAsync(DbCommand command, CommandEventData eventData, InterceptionResultobject result,CancellationToken cancellationToken new CancellationToken()){command.CommandText TableAliasRegex.Replace(command.CommandText,${tableAlias} WITH (NOLOCK));return base.ScalarExecutingAsync(command, eventData, result, cancellationToken);}public override InterceptionResultDbDataReader ReaderExecuting(DbCommand command, CommandEventData eventData, InterceptionResultDbDataReader result){command.CommandText TableAliasRegex.Replace(command.CommandText,${tableAlias} WITH (NOLOCK));return result;}public override TaskInterceptionResultDbDataReader ReaderExecutingAsync(DbCommand command, CommandEventData eventData, InterceptionResultDbDataReader result,CancellationToken cancellationToken new CancellationToken()){command.CommandText TableAliasRegex.Replace(command.CommandText,${tableAlias} WITH (NOLOCK));return base.ReaderExecutingAsync(command, eventData, result, cancellationToken);} } Interceptor 的使用在注册 DbContext 服务的时候可以配置 Interceptor配置如下var services new ServiceCollection(); services.AddDbContextTestDbContext(options {options.UseLoggerFactory(loggerFactory).UseSqlServer(DbConnectionString).AddInterceptors(new QueryWithNoLockDbCommandInterceptor()); }); 使用效果通过 loggerFactory 记录的日志查看查询执行的 sql 语句可以看到查询语句自动加上了 WITH(NOLOCK)Referencehttps://docs.microsoft.com/en-us/sql/t-sql/queries/hints-transact-sql-table?viewsql-server-ver15https://docs.microsoft.com/en-us/ef/core/what-is-new/ef-core-3.0/#interception-of-database-operationshttps://docs.microsoft.com/zh-cn/ef/core/what-is-new/ef-core-3.0/#interception-of-database-operationshttps://github.com/WeihanLi/WeihanLi.EntityFramework/blob/dev/src/WeihanLi.EntityFramework/Interceptors/QueryWithNoLockDbCommandInterceptor.cs
http://www.yutouwan.com/news/336863/

相关文章:

  • 百度网站验证是虚拟主机租赁
  • 网站模板源码平台公司网站建设的工具
  • 做论坛网站赚钱吗做辅食网站
  • 网站鼠标特效代码有哪些网站的搜索引擎
  • 京东商城官方网站一个网站开发流程图
  • 杭州制作网站公司wordpress 菜单 间距
  • 大良网站制作建设网站技术解决方案
  • 哈尔滨php网站开发公司怎么自己做网站发优惠券
  • 织梦网站如何做seo品牌网站建设风格怎么确定
  • 做网站后台指的那成都网站制作培训
  • 12306网站 谁做的大连建设网联合收费
  • win7 iis架设网站深圳网站建设 响应式设计开发
  • 网站建设工期及预算怎么自己做模板网站
  • 柞水县住房和城乡建设局网站整合营销策略有哪些
  • 沙田网站建设公司建设网站服务商
  • 上海建设网站平台微信 微网站开发
  • 怎么做网站超市网页微信客户端手机版
  • 商洛市住房城乡建设厅网站企业信息公示系统年报
  • 哪些网站可以做seo行业开发
  • 网站建设要准备什么资料太原网站设计
  • 公司网站制作步骤流程图丰泰建设集团有限公司网站
  • 外国 网站模板哪个网站做网站好
  • 黄冈做网站的公司哪家好网站建设的市场容量
  • 做网站所需要的代码6网站整体框架
  • 巩义企业网站托管服务商网络图片素材
  • 崇信县门户网站首页销售平台网站建设
  • 赣州哪里可以做网站北京做机柜空调的网站
  • 昌乐网站制作价格3 建设营销型网站流程图
  • 长沙长沙h5网站建设sem扫描电子显微镜
  • 富阳网站建站公司哪家好wordpress cms系统