title: update data using viewmodel
body: <p>I'm trying to update dataEntry using viewmodel and I'm getting this error msg :</p>
  
  <blockquote>
    <p>Store update, insert, or delete statement affected an unexpected
    number of rows (0). Entities may have been modified or deleted since
    entities were loaded.</p>
  </blockquote>
  
  <p>As far as I understand it's showing the ID is missing , but onDebug I can c the foreign id (<code>model.rgrade.SubjectId</code>) I cant finger out how to find the model rgradeId(   in the results.</p>
  
  <p>This is my code :</p>
  
  <pre><code>//checked if the subject name is allready in the db
  var subjectNameQuery = db.Subject.Where(n =&gt; n.SubjectName.ToLower().Equals(model.sub.SubjectName));
  if (subjectNameQuery.Count() &gt; 0)
  {
      //if the name is in the table, do Not add the name of the Id again
      model.rev.SubjectId = subjectNameQuery.SingleOrDefault().SubjectId;
      model.rgrade.SubjectId = subjectNameQuery.SingleOrDefault().SubjectId;
      if (model.rev.GBU == "Good")
      {
          model.rgrade.Good = +1;
      }
      else if (model.rev.GBU == "Bad")
      {
          model.rgrade.bad = +1;
      }
      else if (model.rev.GBU == "Ugly")
      {
          model.rgrade.Ugly = +1;
      }
  
      db.Entry(model.rgrade).State = EntityState.Modified;
  }
  </code></pre>