使用信号器和 sqldependency 在 asp.net core 中的数据库更改通知 [英] Database change notifications in asp.net core using signalr and sqldependency
问题描述
如果我对 SQL 表行进行了任何更改,则 UI 应自动刷新新更改,无需 F5 或重新加载浏览器.
If I made any changes in SQL table row then UI should automatically refresh the new changes without F5 or reloading the browser.
我已经在 asp.net mvc 中尝试过这个并且它运行良好,但我无法在 asp.net mvc 核心中做..
I have already tried this in asp.net mvc and its working good but I'm unable to do in asp.net mvc core..
推荐答案
您可以使用 SqlDependency 类检测更改,然后使用 SignalR 将它们广播给注册的客户端.我使用 pre-Core SignalR 编写了一个示例,该示例可在 https://weblogs.asp.net/ricardoperes/broadcasting-database-changes-through-signalr.为了使其与 ASP.NET Core SignalR 一起使用,您需要使用服务定位器 (HttpContext.RequestServices.GetService>) 检索集线器.此外,您必须对客户端代码进行更改.
You can detect changes using the SqlDependency class and then broadcast them to registered clients using SignalR. I wrote a sample using pre-Core SignalR, which is available at https://weblogs.asp.net/ricardoperes/broadcasting-database-changes-through-signalr. In order to make it work with ASP.NET Core SignalR you need to retrieve the hub using the service locator (HttpContext.RequestServices.GetService>). Also, there is a change that you must do to the client-side code.
这篇关于使用信号器和 sqldependency 在 asp.net core 中的数据库更改通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!