EF Update Specified field ...

Source: Internet
Author: User

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 ...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.