Update the settings for the specified field about the EF update database

Source: Internet
Author: User

1, about EF and the new database update the settings of the specified field

  Perhaps some fields do not want to be updated when EF submits to the database, or update a model to the database yourself!

1. Update data does not update some fields

    /// <summary>        ///database Specifies update fields/// </summary>[HttpGet] PublicHttpresponsemessage Alteruserinfo (intID) {//first Query and then modify            varuser = Dbcontent.k_user. Where (o = o.id = =ID).            FirstOrDefault (); User.Name="Week"; //This property does not want to commit to database modificationUser.age =1; //Set container space a field of a model is not committed to a database//Dbcontent.entry is the entire object to be updated to the databasedbcontent.entry<k_user> (user). Property (" Age"). IsModified =false;            Dbcontent.savechanges (); returnReturnstringdata (User.Name); }
View Code

2. Update method Optimization (not commit to database update when property is null)

3. Add model Updates directly

    

Update the settings for the specified field about the EF update database

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.