EF updates the specified fields ...
Search to find not what they want ...
Perhaps there is a better way to achieve this, so no one to do it ...
If so, please do not hesitate to let us know. Gg..
//to change the columns specified in the UserInfo table, such as the table has 15 columns, if a lot of columns are to be updated, it is necessary to decide which one to update. //Now this is the number of columns to pass, the cycle of updates can be Public stringUserinfo_update_test (stringjsonparames) {Jsonparames="a JSON string";//For example: {"ID": "7", "LoginName": "Modified Login name", "PassWord": "Modified password"}dictionary<string,Object> userinfodic = (dictionary<string,Object>) JSON. Instance.parse (Jsonparames);//need to reference Fastjson assembly intID =0; if(Userinfodic.containskey ("ID")) { int. TryParse (userinfodic["ID"]. ToString (), outID); } vardb =Newdbentities (); UserInfo Info= db. Userinfo.single (U = u.id = =ID); //It was supposed to be a field to judge if (Userinfodic.containskey ("field to update")) {info. The field to update =userinfodic[the field to update];} //because userinfo this table field more ... And there are many other tables to do ... So the following method is used ... #regionMain content ... Used to replace too many if judgments ...foreach(varProinchinfo. GetType (). GetProperties ()) {if(Userinfodic.containskey (pro. Name) {Pro. SetValue (info, Userinfodic[pro. Name]); }} db. SaveChanges ();//This can't be forgotten ... #endregion return NULL; }
EF Update Specified field ...