In my WPF app I have implemented LINQ to SQL query which populates an Observable Collection connected with ListView. It is in this method which I can call from somwhere and it works OK:
private void VisualizeAllShows()
{
MyfirstdbDataContext context = new MyfirstdbDataContext();
_ShowQuCollection.Clear();
var sh = from p in context.Shows select p;
foreach (var p in sh)
_ShowCollection.Add(new ShowsQu
{
Date = p.Date,
Time = p.Time,
Description = p.Description
});
}
Now I need this updating to take place automatically on database table data changing.
Should I use for this purpose this public event in my LINQ to SQL class:
public event PropertyChangedEventHandler PropertyChanged;
If so, please, how to use an event-handler which would fire from data changing?
If no, where I should look for right way to do this?
As far as I know, there is nothing that comes from the database engine that notifies your application of updates to a table on the SQL server. Best bet is to add this using CLR integration on SQL Server, see #3.
These are the options I can think of:
1. Poll for changes by querying the database repeatedly to check for changes.
2. I have seen SqlCacheDependancy used for this, but from what I read it was CPU intensive.
3. Add a CLR assembly to the SQL Server that has code implemented in a trigger, such that updates then run .NET code which notifies your application of the update. If you can get this to work it will probably be the most efficient. I’m not sure though what limitations you have when writing .NET code for a CLR Integration on SQL Server. I.e. whether or not it will let you connect to an external application. How you communicate could vary across any network technology, TCP/IP, WCF, Remoting, etc.