0

I need to know if a new record has been added to a particular table in my windows application. Table might be manipulated by different applications.

For now I'm using a Timer control and querying to see if there is a new record (I add record content somewhere in my application and delete record to avoid getting duplicate record), but of course this is not a clean way for this purpose.

Is there something like an event or something better than my approach?

I'm using entity framework 6

Update: I've read about SqlDependency but I don't know if it can be implemented using entity framework

Saeed mohammadi
  • 199
  • 1
  • 13
  • 1
    While there are duplicate questions (like this: http://stackoverflow.com/questions/5288434/how-to-monitor-sql-server-table-changes-by-using-c), it would be nice to know, what are you trying to achieve with table monitoring? May be, you don't need notifications at client side and it will be enough to use trigger? – Dennis Sep 01 '15 at 12:43

2 Answers2

1

You can give Linq2Cache a try to leverage SqlDependency, last time I hear EF6 was cleaned up its act and now formulates queries which are Query Notifications compatible.

Remus Rusanu
  • 288,378
  • 40
  • 442
  • 569
-2

Here's an existing StackOverflow article about that using the SQLDependency class.

Alternatively, you can cache the last record ID in memory/local to your program (in a file) or write the last processed record ID to a database table and search for anything more recent than that.

Community
  • 1
  • 1
Graham
  • 336
  • 1
  • 13
  • 2
    Please, vote to close as a duplicate, if you're considering this question as a duplicate. – Dennis Sep 01 '15 at 12:44