dumbledad
dumbledad

Reputation: 17527

How should database changes get picked up in LINQ and then bound XAML?

There are lots of great articles and samples showing how to add INotifyPropertyChanged to the LINQ classes mapped to database tables, so that one can bind XAML view elements (like a ListView's ItemsSource) to the LINQ. Abby Fichtner (aka Hacker Chick) has a great example over on Code Project http://www.codeproject.com/Articles/43025/A-LINQ-Tutorial-Mapping-Tables-to-Objects However the examples I've found all assume the changes to the database (row additions, row deletions, and row updates) all come from the LINQ code.

Is there an established pattern for having the LINQ classes pick up database changes? The obvious one is to set up a timer and repeatedly run the select queries to populate the LINQ classes, but I wonder if the binding between the SQL database and the LINQ may have an event for this baked in? It's also not obvious to me whether the refreshed LINQ classes would be able to distinguish new rows from old and thus know whether to raise PropertyChanged events.

How are folk handing this?

Upvotes: 0

Views: 117

Answers (1)

zmbq
zmbq

Reputation: 39013

You need SqlDependencies: http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldependency.aspx . Someone even figured out a way of integrating them with LINQ queries, but you'll need to figure out how good it is on your own: http://rusanu.com/2010/08/04/sqldependency-based-caching-of-linq-queries/

Upvotes: 1

Related Questions