title: Subscribing to EF changes with RX
body: <p>I'm probably totally misunderstanding what RX is all about, but I thought it would be a neat way of allowing various client applications in my code to subscribe to notifications of changes to certain Entity Framework Code First types.</p>
  
  <p>So in my UOW Commit methood I have</p>
  
  <pre><code>        var changes = DbContext.ChangeTracker.Entries&lt;EntEvent&gt;().Where(ee =&gt; ee.State != EntityState.Unchanged);
          Hub.Instance.NotifyBeforeSave(changes);
  </code></pre>
  
  <p>and my (rather basic) hub class looks like this...</p>
  
  <pre><code>public sealed class Hub
  {
      private static readonly Hub instance = new Hub();
      static Hub(){}
      private Hub(){}
      public static Hub Instance
      {
          get { return instance; }
      }
  
      public IObservable&lt;System.Data.Entity.Infrastructure.DbEntityEntry&lt;EntEvent&gt;&gt; BeforeSave = new Subject&lt;DbEntityEntry&lt;EntEvent&gt;&gt;(); 
      public void NotifyBeforeSave&lt;T&gt;(IEnumerable&lt;System.Data.Entity.Infrastructure.DbEntityEntry&lt;T&gt;&gt; changes) where T:class
      {
          var  x = changes.Where(c =&gt; typeof(T) == typeof(EntEvent)) as IEnumerable&lt;System.Data.Entity.Infrastructure.DbEntityEntry&lt;EntEvent&gt;&gt;;
          BeforeSave = x.ToObservable();
      }
  }
  </code></pre>
  
  <p>and then I thought I could subscribe a client (observer) by creating an instance of the following and calling attach.</p>
  
  <pre><code>public class SampleConsumer : IObserver&lt;DbEntityEntry&lt;EntEvent&gt;&gt;
  {
      public void attach()
      {            
          Hub.Instance.BeforeSave.Subscribe(this);
      }
  
      public void OnNext(DbEntityEntry&lt;EntEvent&gt; value)
      {
          var x = value;
      }
  
      public void OnError(Exception error)
      {
          var y = error;
      }
  
      public void OnCompleted()
      {
      }
  }
  </code></pre>
  
  <p>but breakpoints in OnNext and OnError never get called.</p>
  
  <p>I'm probably 180deg away from where I should be, but we have to start somewhere!</p>