简体   繁体   English

使用SignalR(实时)从数据库获取更新的方法?

[英]Way to get updates from database with SignalR (real time)?

Is there a way to get database's exist fields and new fields with SignalR? 有没有办法通过SignalR获取数据库的现有字段和新字段?

I would like to make a multi chat application with MVC; 我想和MVC一起做一个多聊天应用程序; and I would like to store all messages etc. in sql server database... 我想在sql server数据库中存储所有消息等...

Planned rotation of the data will be client=>sql server=>client... 计划轮换的数据将是client => sql server => client ...

The technology is new or unknown so I couldn't find smart examples... 这项技术是新的还是未知的,所以我找不到聪明的例子......

check this article and you should be able to save all incomming messages to DB on OnReceivedAsync Method. 查看本文,您应该能够在OnReceivedAsync方法上将所有包含消息保存到DB。

http://visualstudiomagazine.com/articles/2013/01/22/build-a-signal-r-app-part-1.aspx http://visualstudiomagazine.com/articles/2013/01/22/build-a-signal-r-app-part-1.aspx

if you need to send last 20 records to any specific user or broadcast you can use below statement once you fetched last 20 records from you DB. 如果您需要将最后20条记录发送给任何特定用户或广播,您可以在从DB获取最后20条记录后使用以下语句。

Connection.Broadcast(chatData); // this will broadcast data to all connected clients.

protected override Task OnConnectedAsync(IRequest request, string connectionId)
{
    _clients.Add(connectionId, string.Empty);
    ChatData chatData = new ChatData("Server", "A new user has joined the room.");
    return Connection.Broadcast(chatData);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM