Quantcast
Channel: entityframework Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1793

New Post: Automatically detect and refresh data changes in EF6

$
0
0
Hi,

it would be a great feature in EF6 to automatically detect and refresh data changes. I'm using DbContext and DbSet.

A very good approach is described in Harry von Borstel's article
"AutoRefresh Entity Framework Data Using SQL Server Service Broker"
http://www.codeproject.com/Articles/233770/AutoRefresh-Entity-Framework-data-using-SQL-Server


There are two problems with that solution:
  1. Sometimes the refresh triggered by the CallContext is faster than then the reread of the changed entities. When using timestamps to prevent unintended overwrites of data SaveChanges results in an exception:
    System.InvalidOperationException
    HResult=0x80131509, COR_E_INVALIDOPERATION
    The changes to the database were committed successfully, but an error occurred while updating the object context. The ObjectContext might be in an inconsistent state. Inner exception message: AcceptChanges cannot continue because the object's key values conflict with another object in the ObjectStateManager. Make sure that the key values are unique before calling AcceptChanges.
  2. The need of the AutoRefreshWrapper class to handle the CollectionChanged event. It is required, because the event is fired in another tread and must be dispatched to the main thread:
System.Windows.Application.Current.Dispatcher.BeginInvoke((Action)(notifyRefresh.OnRefresh));
That could be avoided with a delegate.


I tried another approach using SqlDependency and a DataTable to track changes. Unfortunately a second connection is needed and every monitored table needs a second query.


Regards
Mathias

Viewing all articles
Browse latest Browse all 1793

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>