c# - Try/Catch Fails When Trying to Extract EntityValidationErrors -


i'm experiencing problem program cannot save db. receive "validation failed 1 or more entities. see 'entityvalidationerrors' property more details." went online , found articles applying try/catch around "savechanges()". project in mvc. project works locally without issue when push live when receive error message.

entityvalidationerrors

controller

//     // get: /account/logoff      [authorize]     public actionresult logoff()     {             // user information             var user = membership.getuser();             var userid = (int)user.provideruserkey;             var userprofile = db.userprofiles.where(up => up.userid == userid).single();              // used display notifications, last login date set when user logs off             var profile = db.userprofiles.where(up => up.userid == userid).single();             profile.lastlogindate = datetime.now.addhours(2);             db.entry(profile).state = entitystate.modified;              try             {                 // doing logic here                 db.savechanges();             }             catch (dbentityvalidationexception dbex)             {                 foreach (var validationerrors in dbex.entityvalidationerrors)                 {                     foreach (var validationerror in validationerrors.validationerrors)                     {                         trace.traceinformation("property: {0} error: {1}", validationerror.           propertyname, validationerror.errormessage);                     }                 }              }              formsauthentication.signout();             return redirecttoaction("logon", "account"); // return user login screen     } 

debugger


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -