title: BeforeSave Validation with EF Code-FIrst
body: <p>I'm attempting to isolate my custom entity validation logic.</p>
  
  <p>I see the following: <a href="https://blogs.msdn.microsoft.com/alexj/2009/07/20/tip-27-how-to-implement-beforesave-validation/" rel="nofollow">https://blogs.msdn.microsoft.com/alexj/2009/07/20/tip-27-how-to-implement-beforesave-validation/</a></p>
  
  <p>However when I attempt this: </p>
  
  <pre><code>public partial class ApplicationContext {
       public void Validate() 
    { 
      var stateEntries = ObjectStateManager.GetObjectStateEntries( 
                                EntityState.Added | 
                                EntityState.Modified | 
                                EntityState.Deleted ) 
                        .Where(e =&gt; e.Entity is IValidingEntity);
  
      foreach (var stateEntry in stateEntries) 
      { 
          var entity = stateEntry.Entity as IValidingEntity; 
          entity.Validate(stateEntry.State); 
      }              
    }
  }
  </code></pre>
  
  <p>I get <code>Cannot access non-static method GetObjectStateEntries in a static context</code>, where <code>ApplicationContext</code> is:</p>
  
  <pre><code>public class ApplicationContext : DbContext {}
  </code></pre>
  
  <p>How can I get this working?</p>