title: Setting IsModified on EntityFramework Decimal Property
body: <p>I'm somewhat new to EF, and trying to make an UPDATE method in REST style that will take one or more properties in an object and update the database with just those I passed in.</p>
  
  <p>I have the code below working for several types.  However, i recently added System.Decimal, and am getting an error that I can't use the Property() method because my decimal field is not a Primitive or complex type.  The error occurs on the following line:</p>
  
  <pre><code> pt.Property(propertyInfo.Name).IsModified = true;
  </code></pre>
  
  <p>The actual error message is:</p>
  
  <p>Additional information: The property 'Miles' on type 'Appointment' is not a primitive or complex property. The Property method can only be used with primitive or complex properties. Use the Reference or Collection method.</p>
  
  <p>My property "Miles" is an 18,2 decimal in SQL and decimal on the EF class as well as my data model class.</p>
  
  <p>I've spent two days searching for any clues or solutions, but got nowhere.  Help me obi wan kenobi, you're my only hope...</p>
  
  <pre><code>    [ResponseType(typeof(void))]
      public async Task&lt;IHttpActionResult&gt; PutAppointment(int id,[FromBody] DTO.Appointment appointment)
      {
          // Check for invalid model and mis-matched ID
          if (!ModelState.IsValid){ return BadRequest(ModelState); }
          if (id != appointment.AppointmentID) { return BadRequest(); }
  
          // Create and populate an Appointment Entity which we will use for saving our data later
          Appointment tempAppt = new Appointment();
          tempAppt.AppointmentID = appointment.AppointmentID;
          db.Appointments.Attach(tempAppt);
          var pt = db.Entry(tempAppt);
  
          // Loop through all the properties on the object that was passed into this method
          //  and update the Entity with any that were provided.
          foreach (PropertyInfo propertyInfo in appointment.GetType().GetProperties())
          {
              if (propertyInfo.CanRead)
              {
                  switch (propertyInfo.PropertyType.ToString())
                  {
                      case "System.Int32":
                          if ((int)propertyInfo.GetValue(appointment) != -1)
                          {
                              pt.Property(propertyInfo.Name).CurrentValue = (int)propertyInfo.GetValue(appointment);
                              pt.Property(propertyInfo.Name).IsModified = true;
                          }
                          break;
                      case "System.Decimal":
                          if ((decimal)propertyInfo.GetValue(appointment) != -1)
                          {
                              propertyInfo.SetValue(appointment, (decimal)propertyInfo.GetValue(appointment));
                              pt.Property(propertyInfo.Name).IsModified = true;
                          }
                          break;
                      case "System.String":
                          if ((string)propertyInfo.GetValue(appointment) != "NONE")
                          {
                              pt.Property(propertyInfo.Name).CurrentValue = (string)propertyInfo.GetValue(appointment);
                              pt.Property(propertyInfo.Name).IsModified = true;
                          }
                          break;
                      case "System.DateTime":
                          if ((DateTime)propertyInfo.GetValue(appointment) != new DateTime(2099, 1, 1))
                          {
                              pt.Property(propertyInfo.Name).CurrentValue = (DateTime)propertyInfo.GetValue(appointment);
                              pt.Property(propertyInfo.Name).IsModified = true;
                          }
                          break;
                      case "System.TimeSpan":
                          if ((TimeSpan)propertyInfo.GetValue(appointment) != new TimeSpan(0))
                          {
                              pt.Property(propertyInfo.Name).CurrentValue = (TimeSpan)propertyInfo.GetValue(appointment);
                              pt.Property(propertyInfo.Name).IsModified = true;
                          }
                          break;
                      //case "System.Nullable`1[System.Guid]":
                      case "System.Guid":
                          if ((Guid)propertyInfo.GetValue(appointment) != new Guid("00000000-0000-0000-0000-000000000000"))
                          {
                              pt.Property(propertyInfo.Name).CurrentValue = (Guid)propertyInfo.GetValue(appointment);
                              pt.Property(propertyInfo.Name).IsModified = true;
                          }
                          break;
                  }
              }
          }
  </code></pre>