[RESOLVED]Code First EF 6 – Real Time Notifications

Currently I have a web application developed using:

  1. Code First
  2. Entity Framework 6
  3. Sql Server 2008 r2
  4. MVC 5

For now everything seems to be going well. Now there arose a new need by our client which is you need to view posts from blogs in real time, what I mean is that I show the changes that are made to the database each time some user makes one insertion.

I have read a lot about SignalR, and its integration with .net on the corresponding pages. I followed some tutorials where a chat room to develop and there has not arisen any problem.

The problem comes when I want to use my SQL Server to retrieve information, tutorials routed me to use SQL Dependency but as I am using Code First Entity Framework is not where it down, I’m really a bit confused and not sure whether to use SignalR is the
best option for my notifications in real time.

Thanks in advance!

This article shows how to use SignalR with EF to provide real-time notifications: http://developer.telerik.com/products/realtime-data-with-signalr-and-websockets/

Mike, thanks for your answer.

I already try that example and in Kendo works good, but I have had problems passing parameters. When I try  develop for normal notifications (not in Kendo) I can’t, I always end up directed to the use of Sql Dependency.  So I don’t know if SignalR is the
best way to develop Real-Time Notifications

Thank you!

you are confusing two concepts

1) realtime detection of database changes. sqldependency is used for this. EF does not support it directly, but you can use the EF context to get the connection string and use the same tables.

2) realtime communication between web browser and web server. signal/r is the .net library for this. a blog written with signal/r would not need sqldepency if only the signal/r code preforms the blog updates. it could just  update client of a data change,
when it made a change.

Bruce, thanks for clarification. In this order.

If I use SignalR for notifications of my blog, how do I know when a user makes a change in the database? and the same time shows the updates in the blog? What should I use?

Thanks!

Hi,

You need to use both of SignalR and SqlDependency.

About SqlDependency notification in EF, please refer to:

# How to use SqlDependency to get the notification in Entity Framework

https://code.msdn.microsoft.com/How-to-use-SqlDependency-5c0da0b3

About notification in ASP.NET using SinalR and SqlDependency, please refer to:

# Database Change Notifications in ASP.NET using SignalR and SqlDependency

http://techbrij.com/database-change-notifications-asp-net-signalr-sqldependency

Best Regards

Starain

Thanks.

I’ve finally done it!

Leave a Reply