4

I am working on integrations so I am building an api in .NET Core 2 and Entity Framework 7 for a system that was built in ASP.NET MVC 5 and EF 6 to communicate with other API's. Here is an image of what it looks like

enter image description here

I would like my asp.net core 2 API to listen to changes in SQL Server rather than being notified by the MVC app every time a change happens.

I read this article here sqldependency. SQLdependency is around 15 years old, is this still the standard way of listening to DB changes or is there another way I could do this?

Train
  • 3,420
  • 2
  • 29
  • 59
  • 1
    Be cautious before using SqlDependency. It requires Service Broker and if you're using SQL Azure - or think you may - it isn't available unless you have a managed instance - so first check you can even enable it before writing any code! – Simon_Weaver Jun 26 '19 at 22:10
  • @Simon_Weaver Thanks! So I decided not to go this route. Also it was a private server not a chance of using azure. – Train Jun 27 '19 at 17:06
  • I wasted way too much time reading all about SqlDependency yesterday, writing code then found I can’t even use it. Interesting to see how it works though - so the day after I’m glad I at least understand it now! Wasn’t happy yesterday though! – Simon_Weaver Jun 27 '19 at 17:08

1 Answers1

4

In Ado.net were a class SqlDependency for that kind of notification, on EF do not supported, but here are some samples

https://web.archive.org/web/20150916155640/https://code.msdn.microsoft.com/How-to-use-SqlDependency-5c0da0b3

www.codeproject.com/Articles/496484/SqlDependency-with-Entity-Framework

And in this question talk about some issues

Is SqlDependency supported in .NET Core?

petrosmm
  • 528
  • 9
  • 23
Programudo
  • 56
  • 2