title: Detect state change of model property, in controller, using Entity Framework
body: <p>I have a more or less standard looking model:</p>
  
  <pre><code>public class Project {
    public int ID { get; set; }
    //... some more properties
  
    public DateTime StartDate { get; set; }
    public int Duration { get; set; }
  }
  </code></pre>
  
  <p>If the user modifies <code>StartDate</code> or project <code>Duration</code>, I have to call a function to update a simulation. In order to achieve this I'd like to detect the state change of the fields <code>StartDate</code> and <code>Duration</code> within a controller.</p>
  
  <p>Something like that:</p>
  
  <pre><code>if(project.StartDate.stateChange() || project.Duration.stateChange())
  </code></pre>
  
  <p>Here is an example of what the Controller Method would look like:</p>
  
  <pre><code>[HttpPost]
  public ActionResult Edit(Project project)
  {
      if (ModelState.IsValid)
      {
          if(project.StartDate.stateChange() || project.Duration.stateChange())
              doSomething();
  
          db.Entry(project).State = EntityState.Modified;
          db.SaveChanges();
          return RedirectToAction("Index");
      }
      return View(project);
  }
  </code></pre>
  
  <p>Any idea, how can I achieve this?</p>