更新时间:2023-02-13 22:14:38
您可以使用 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.