entity framework - Setting IsModified on EntityFramework Decimal Property -


i'm new ef, , trying make update method in rest style take 1 or more properties in object , update database passed in.

i have code below working several types. however, added system.decimal, , getting error can't use property() method because decimal field not primitive or complex type. error occurs on following line:

 pt.property(propertyinfo.name).ismodified = true; 

the actual error message is:

additional information: property 'miles' on type 'appointment' not primitive or complex property. property method can used primitive or complex properties. use reference or collection method.

my property "miles" 18,2 decimal in sql , decimal on ef class data model class.

i've spent 2 days searching clues or solutions, got nowhere. me obi wan kenobi, you're hope...

    [responsetype(typeof(void))]     public async task<ihttpactionresult> putappointment(int id,[frombody] dto.appointment appointment)     {         // check invalid model , mis-matched id         if (!modelstate.isvalid){ return badrequest(modelstate); }         if (id != appointment.appointmentid) { return badrequest(); }          // create , populate appointment entity use saving our data later         appointment tempappt = new appointment();         tempappt.appointmentid = appointment.appointmentid;         db.appointments.attach(tempappt);         var pt = db.entry(tempappt);          // loop through properties on object passed method         //  , update entity 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;                 }             }         } 

as usual, when have problem takes more couple hours solve, comes down stupid.

my data/business object using upper case "m" on "miles" , database (and consequently ef) using lower case "m" on "miles". once gave , changed data type had working, became obvious wasn't type issue. had stare @ long enough notice case problem.

as were...


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -