For EF database update, update the settings of the specified field, ef Field

Source: Internet
Author: User

For EF database update, update the settings of the specified field, ef Field

1. Set the update field for EF and the new database

When EF is submitted to the database, some fields may not want to be updated, or you can update a model to the database by yourself!

1. Update data without updating some fields

/// <Summary> /// specify the update field in the database /// </summary> [HttpGet] public HttpResponseMessage alterUserInfo (int id) {// query and modify var user = DbContent. k_user.Where (o => o. id = id ). firstOrDefault (); user. name = "Week"; // you do not want to submit this attribute to the database to modify the user. age = 1; // set a field of a model in the container space not to be submitted to the database. // DbContent. the Entry is the entire object DbContent to be updated to the database. entry <k_user> (user ). property ("age "). isModified = false; DbContent. saveChanges (); return returnStringData (user. name );}
View Code

2. Update method optimization (database update is not submitted when the attribute is null)

3. directly add model updates

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.